1. 程式人生 > >Laravel 5.3+ Auth::routes 驗證路徑

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\[email protected]')->name('login'
); $this->post('login', 'Auth\[email protected]'); $this->post('logout', 'Auth\[email protected]')->name('logout'); // Registration Routes... $this->get('register', 'Auth\[email protected]')->name('register'); $this->post('register'
, 'Auth\[email protected]'); // Password Reset Routes... $this->get('password/reset', 'Auth\[email protected]')->name('password.request'); $this->post('password/email', 'Auth\[email protected]')->name('password.email'); $this->get('password/reset/{token}', 'Auth\[email protected]')->name('password.reset'); $this->post('password/reset', 'Auth\[email protected]'); } ... }

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();
    }
    ...
}