简体   繁体   English

laravel中的Auth :: routes()和Route :: auth()有什么区别

[英]what is the difference between Auth::routes() and Route::auth() in laravel

I have start working on laravel 5.4 , i have found that there is Auth::routes() which is called default in web route . 我已经开始研究laravel 5.4 ,我发现有Auth::routes()网络路由中称为default。 I want to more clear with the difference between Auth::routes() and Route::auth() . 我想更清楚地了解Auth::routes()Route::auth()的区别。

Using Auth::routes() or Route::auth() is equivalent. 使用Auth::routes()Route::auth()是等效的。 Infact Auth::routes() is defined as: 实际Auth::routes()定义为:

/**
 * Register the typical authentication routes for an application.
 *
 * @return void
 */
public static function routes()
{
    static::$app->make('router')->auth();
} 

where $app->make('router') returns an Illuminate\\Routing\\Router instance just like the facade Route does. 其中$app->make('router')返回一个Illuminate\\Routing\\Router实例,就像外观Route一样。

Route::auth() will create the following routes (as found in Illuminate\\Routing\\Router.php : 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() will call the following function (as found in Illuminate\\Support\\Facades\\Auth.php ): 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();
}

As you can see, the second method creates an instance of the first Router class and calls the auth() function on it. 如您所见,第二个方法创建第一个Router类的实例,并在其上调用auth()函数。 In the end there is no difference in the two methods. 最后,这两种方法没有区别。 If you have a choice I would personally advice using Route::auth() since that seems to be the "default" implementation. 如果您有选择,我个人会建议使用Route::auth()因为这似乎是“默认”实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM