Laravel 5.3+ 開始,添加了Auth()::routes()
路徑組,其中註冊了常見的驗證路徑,例如註冊,登錄登出,以及密碼修改。
在web.php
中,添加如下代碼:
Auth()::routes()
即可使用這些路徑。
而要查看這些路徑具體包含了哪些,我們可以打開\vendor
文件夾中Laravel
的Router.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();
}
...
}