laravel 5.3 new Auth :: routes()
最近我开始用laravel 5.3写博客,但是运行php artisan make:auth
后有个问题
当我运行这个,它会在我的web.php
生成路由
这是它的代码:
Auth::routes(); Route::get('/home', 'HomeController@index');
然后我运行php artisan route:list
,我发现很多行动,如LoginController @login…
但是我没有在App\Http\Controllers\Auth
find这些动作,这些在哪里?
而且什么是Auth::routes()
代表,我找不到关于Auth的路由。
我需要人帮忙,谢谢你回答我的问题
Auth :: routes()只是一个帮助类,可以帮助您生成用户authentication所需的所有路由。 你可以浏览https://github.com/laravel/framework/blob/5.3/src/Illuminate/Routing/Router.php代码。;
这里是路线
// 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'); $this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail'); $this->get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm'); $this->post('password/reset', 'Auth\ResetPasswordController@reset');
Auth路由为Laravel 5.3而不是Auth :: routes()。 我希望这有助于…
Route::group(['middleware' => ['web']], function() { // Login Routes... Route::get('login', ['as' => 'login', 'uses' => 'Auth\LoginController@showLoginForm']); Route::post('login', ['as' => 'login.post', 'uses' => 'Auth\LoginController@login']); Route::post('logout', ['as' => 'logout', 'uses' => 'Auth\LoginController@logout']); // Registration Routes... Route::get('register', ['as' => 'register', 'uses' => 'Auth\RegisterController@showRegistrationForm']); Route::post('register', ['as' => 'register.post', 'uses' => 'Auth\RegisterController@register']); // Password Reset Routes... Route::get('password/reset', ['as' => 'password.reset', 'uses' => 'Auth\ForgotPasswordController@showLinkRequestForm']); Route::post('password/email', ['as' => 'password.email', 'uses' => 'Auth\ForgotPasswordController@sendResetLinkEmail']); Route::get('password/reset/{token}', ['as' => 'password.reset.token', 'uses' => 'Auth\ResetPasswordController@showResetForm']); Route::post('password/reset', ['as' => 'password.reset.post', 'uses' => 'Auth\ResetPasswordController@reset']); });
所以如果你改变这些路线的名字,记得在视图中改变post的动作!
函数调用顺序:
- (Auth)Illuminate \ Support \ Facades \ Auth @ routes( https://github.com/laravel/framework/blob/5.3/src/Illuminate/Support/Facades/Auth.php )
- (APP)照亮\基金会\应用@权威性
- (路线)照亮\路由\路由器
这是这样的路线:
public function auth() { // Authentication Routes... $this->get('login', 'Auth\AuthController@showLoginForm'); $this->post('login', 'Auth\AuthController@login'); $this->get('logout', 'Auth\AuthController@logout'); // Registration Routes... $this->get('register', 'Auth\AuthController@showRegistrationForm'); $this->post('register', 'Auth\AuthController@register'); // Password Reset Routes... $this->get('password/reset/{token?}', 'Auth\PasswordController@showResetForm'); $this->post('password/email', 'Auth\PasswordController@sendResetLinkEmail'); $this->post('password/reset', 'Auth\PasswordController@reset'); }
对于Laravel 5.5.x
// 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');
loginuser类使用称为AuthenticatesUsers
的特征
如果你打开这个特性,你会看到这个function(这适用于其他控制器) Illuminate\Foundation\Auth\AuthenticatesUsers;
这里是特质代码https://github.com/laravel/framework/blob/5.1/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php
抱歉的格式不好,即时通讯使用我的手机
也Auth::routes()
它只是调用一个函数,返回authentication路线多数民众赞成它(我认为)