![](/img/trans.png)
[英]What is the difference between auth and access in Laravel 5.7?
[英]what is the difference between Auth::routes() and Route::auth() in laravel
我已经开始研究laravel 5.4 ,我发现有Auth::routes()
在网络路由中称为default。 我想更清楚地了解Auth::routes()
和Route::auth()
的区别。
使用Auth::routes()
或Route::auth()
是等效的。 实际Auth::routes()
定义为:
/**
* Register the typical authentication routes for an application.
*
* @return void
*/
public static function routes()
{
static::$app->make('router')->auth();
}
其中$app->make('router')
返回一个Illuminate\\Routing\\Router
实例,就像外观Route
一样。
Route::auth()
将创建以下路由(如在Illuminate\\Routing\\Router.php
找到的Illuminate\\Routing\\Router.php
:
/**
* Register the typical authentication routes for an application.
*
* @return void
*/
public function auth()
{
// Authentication Routes...
$this->get('login', 'Auth\LoginController@showLoginForm')->name('login');
$this->post('login', 'Auth\LoginController@login');
$this->post('logout', 'Auth\LoginController@logout')->name('logout');
// Registration Routes...
$this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
$this->post('register', 'Auth\RegisterController@register');
// Password Reset Routes...
$this->get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
$this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
$this->get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
$this->post('password/reset', 'Auth\ResetPasswordController@reset');
}
Auth::routes()
将调用以下函数(如在Illuminate\\Support\\Facades\\Auth.php
):
/**
* Register the typical authentication routes for an application.
*
* @return void
*/
public static function routes()
{
static::$app->make('router')->auth();
}
如您所见,第二个方法创建第一个Router
类的实例,并在其上调用auth()
函数。 最后,这两种方法没有区别。 如果您有选择,我个人会建议使用Route::auth()
因为这似乎是“默认”实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.