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

本文介绍了Laravel 5.3及更高版本中`Auth::routes()`方法如何注册验证相关路径,如注册、登录、登出和密码修改。通过在路由文件中添加特定代码,开发者可以便捷地利用这些预定义的路径。同时,文章指导读者如何查看具体的路径定义,即在`routes/web.php`文件内找到相应函数。
190

被折叠的 条评论
为什么被折叠?



