簡體   English   中英

laravel中的Auth :: routes()和Route :: auth()有什么區別

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM