Laravel 5.3+ Auth::routes 驗證路徑

Laravel 5.3+ 開始,添加了Auth()::routes()路徑組,其中註冊了常見的驗證路徑,例如註冊,登錄登出,以及密碼修改。

web.php中,添加如下代碼:

Auth()::routes()

即可使用這些路徑。

而要查看這些路徑具體包含了哪些,我們可以打開\vendor文件夾中LaravelRouter.php文件:

/* \vendor\laravel\framework\Illuminate\Routing\Router.php */

namespace Illuminate\Routing;
...
class Router implements RegistrarContract, BindingRegistrar
{
    ...
    /**
     * 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 Facade中,可以看到註冊這些路徑的函數:

namespace Illuminate\Support\Facades;
...
class Auth extends Facade
{
    ...
    /**
     * Register the typical authentication routes for an application.
     *
     * @return void
     */
    public static function routes()
    {
        static::$app->make('router')->auth();
    }
    ...
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章