版权声明:尊重原创喔,转载请注明 https://blog.csdn.net/lgyaxx/article/details/79207126
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();
}
...
}