php - 我想知道 web.php 中使用的类 Route

标签 php laravel routes

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

问题是,那个类对我来说是一个谜,我在我的 laravel 项目中找不到它的源代码,我在 Internet 上也找不到任何关于它的信息。 如果你用谷歌搜索,你会找到 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');

最佳答案

你快到了;

您会在 Illuminate\Routing\Router 类下找到它。

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

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

关于php - 我想知道 web.php 中使用的类 Route,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41366451/

相关文章:

Linux - 通过以太网路由特定流量

php - APC 的 ZF2 PHP5.5 缓存存储替代品

orm - Laravel:我如何循环遍历 ORM 的字段和关系

php - 每个用户都可以创建一个具有窗帘功能的组,其他用户可以加入?数据库设计

amazon-web-services - 了解 AWS 路由表 - 无法创建更具体的路由

ruby-on-rails - 如何路由用户配置文件 URL 以跳过 Controller ?

php - 使用 PHP 将 CSV 转换为 JSON

php - 不同的 pi 值?

php - 有什么好的 php5 OOP 教程网站吗?

php - Laravel - 如果登录凭据错误,则在同一页面上显示错误