![](/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.