我想了解 web.php 中使用的 Route 类

Sca*_*ass 5 php routes laravel

所以,在Laravel中,有一个web.php文件,其中使用了Route类,并调用了它的静态函数get和matched。

问题是,这个类对我来说有点神秘,我在我的 laravel 项目中找不到它的源代码,我也无法在互联网上找到任何关于它的信息。如果你用谷歌搜索,你会找到 Illuminate\Routing\Route 但我认为这不是我要找的类,因为那个类没有静态函数 get 和 match。我也尝试在我的项目目录中查找它,我发现有四个具有此类名称的类,但它们都没有在我的 web.php 中使用的这些函数。

这是我的 web.php:

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Auth::routes();

Route::get('/', 'BlogController@all')->name('post.all');

Route::match(['get', 'post'], '/article/create', 'BlogController@create')->name('post.create')
     ->middleware('auth');

Route::get('/article/{id}', 'BlogController@single')->name('post.single');

Route::match(['get', 'post'], '/article/{id}/delete', 'BlogController@delete')->name('post.delete')
     ->middleware('auth', 'author');

Route::match(['get', 'post'], '/article/{id}/edit', 'BlogController@edit')->name('post.edit')
     ->middleware('auth', 'author');

Route::get('/author/{id}', 'BlogController@author')->name('post.author');

Route::get('/category/{id}', 'BlogController@category')->name('post.category');

Route::match(['get', 'post'], '/user/create', 'UserController@create')->name('user.create')
     ->middleware('auth');

Route::get('/home', 'HomeController@index');
Run Code Online (Sandbox Code Playgroud)

Six*_*dio 3

你快到了;

您会在课程下找到它Illuminate\Routing\Router

您在这里看不到静态函数的原因是 Laravel 使用称为“Facades”的东西,它提供了访问实例化类的静态方法。它本质上包装了 Route 类并为您调用这些函数。

通过查看aliases 键,您可以看到Route注册到 Laravel 的所有外观(包括外观) 。config/app.php