2016-08-29 97 views
44

最近,我開始使用laravel 5.3寫博客,但我有php artisan make:authlaravel 5.3新驗證::路線()

,當我運行它,它會在我的web.php

生成路線運行後一個問題

這是它的代碼:

Auth::routes(); 

Route::get('/home', '[email protected]'); 

然後我跑php artisan route:list,我發現很多的操作,如LoginController中@登錄...

但我沒有在我的App\Http\Controllers\Auth中找到這些行爲,這些在哪裏?

還有什麼是Auth::routes()代表,我無法找到關於Auth的路由。

我需要有人幫助,謝謝你回答我的問題

回答

84

驗證::路由()僅僅是一個輔助類,可幫助您生成所有用戶認證所需的路由功能。您可以在這裏瀏覽代碼https://github.com/laravel/framework/blob/5.3/src/Illuminate/Routing/Router.php

下面是路由

// 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]'); 
$this->post('password/email', 'Auth\[email protected]'); 
$this->get('password/reset/{token}', 'Auth\[email protected]'); 
$this->post('password/reset', 'Auth\[email protected]'); 
+0

謝謝!我看到../Routing/Router.php,現在我知道路由是如何工作的。但Auth靜態方法routes()在哪裏?我仍然無法找到它,原諒我我是laravel初學者... – g1eny0ung

+1

Auth :: routes方法在這裏https://github.com/laravel/framework/blob/5.3/src/Illuminate/Support/Facades/ Auth.php及其調用路由器功能。 請標記爲答案,如果這有助於你,謝謝。 – Lee

+1

'Auth'是一個*外觀*,將在'config/app.php'中定義。您將在該配置文件中找到充當其提供者的類。 – Jason

0

的loginuser類使用了一個名爲特質AuthenticatesUsers

如果您打開特質,你會看到的功能(適用於其它控制器) Illuminate\Foundation\Auth\AuthenticatesUsers;

這裏是特徵代碼https://github.com/laravel/framework/blob/5.1/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php

遺憾的格式錯誤,即時通訊使用我的手機

Auth::routes()它只是調用返回AUTH路線完蛋了(我認爲)

+0

是的,我期待通過認證/目錄,但我沒有找到方法,例如App \ HTTP \控制器\身份驗證\ ResetPasswordController @ showResetForm,我在哪裏可以找到方法@後,我花很多時間找到它,但現在我也無法找到它..我是laravel的新手.. – g1eny0ung

+1

這裏是完整路徑'vendor \ laravel \ src \ Illuminate \ Foundation \ Auth \ ResetsPasswords',如果你想改變這個或其他東西,不要改變這一點,只需將相同的方法添加到你的控制器,然後改變它, –

+0

@Achraf Khouadja,看來你是主人laravel。我需要你幫忙。看看這裏:http://stackoverflow.com/questions/41047583/how-to-add-dynamic-dropdown-list-column-on-laravel-5-3-registration –

31

爲Laravel 5.3代替驗證::路由()驗證路由。 我希望它可以幫助...

Route::group(['middleware' => ['web']], function() { 

// Login Routes... 
    Route::get('login', ['as' => 'login', 'uses' => 'Auth\[email protected]']); 
    Route::post('login', ['as' => 'login.post', 'uses' => 'Auth\[email protected]']); 
    Route::post('logout', ['as' => 'logout', 'uses' => 'Auth\[email protected]']); 

// Registration Routes... 
    Route::get('register', ['as' => 'register', 'uses' => 'Auth\[email protected]']); 
    Route::post('register', ['as' => 'register.post', 'uses' => 'Auth\[email protected]']); 

// Password Reset Routes... 
    Route::get('password/reset', ['as' => 'password.reset', 'uses' => 'Auth\[email protected]']); 
    Route::post('password/email', ['as' => 'password.email', 'uses' => 'Auth\[email protected]']); 
    Route::get('password/reset/{token}', ['as' => 'password.reset.token', 'uses' => 'Auth\[email protected]']); 
    Route::post('password/reset', ['as' => 'password.reset.post', 'uses' => 'Auth\[email protected]']); 
}); 

因此,如果您更改這些路線的一些名字,記得要在意見職位的行動也改變!

2

函數調用順序:

  1. (AUTH)提供照明的\ Support \外立面\驗證@路線 (https://github.com/laravel/framework/blob/5.3/src/Illuminate/Support/Facades/Auth.php
  2. (應用程序)提供照明\基金會\應用@權威性
  3. (路線)照亮\路徑\路由器

它的路線是這樣的:

public function auth() 
{ 
    // Authentication Routes... 
    $this->get('login', 'Auth\[email protected]'); 
    $this->post('login', 'Auth\[email protected]'); 
    $this->get('logout', 'Auth\[email protected]'); 
    // Registration Routes... 
    $this->get('register', 'Auth\[email protected]'); 
    $this->post('register', 'Auth\[email protected]'); 
    // Password Reset Routes... 
    $this->get('password/reset/{token?}', 'Auth\[email protected]'); 
    $this->post('password/email', 'Auth\[email protected]'); 
    $this->post('password/reset', 'Auth\[email protected]'); 
} 
+0

https://github.com/laravel/framework/blob/5.3/src/Illuminate/Routing/Router.php#L298 –

7

對於Laravel 5.5。X

// 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]');