繁体   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