2016-03-24 40 views
1

我剛開始了一個laravel 5.2應用程序。我採取的每條路線(/ register,/ logout,login,...)都會將我重定向到主頁。Laravel 5.2 - 每條路線重定向到主頁

這裏是我的路線

<?php 
Route::group(['middleware' => ['web']], function() { 
//Register 
    Route::get('/register', 'Auth\[email protected]'); 
    Route::get('/register/success', 'Auth\[email protected]'); 

    Route::post('/register', 'Auth\[email protected]'); 

//Login 
    Route::get('/login', 'Auth\[email protected]'); 

    Route::post('/login', 'Auth\[email protected]'); 

//Password Reset 
    Route::get('/password/reset/email', 'Auth\[email protected]'); 
    Route::get('/password/reset/{token}', 'Auth\[email protected]'); 
    Route::get('/password/reset/sent', 'Auth\[email protected]'); 

    Route::post('/password/reset/email', 'Auth\[email protected]'); 
    Route::post('/password/reset', 'Auth\[email protected]'); 
}); 


Route::group(['middleware' => ['web', 'auth']], function() { 
    Route::get('/logout', 'Auth\[email protected]'); 
}); 

Route::get('/', function() { 
    return view('welcome'); 
}); 

當我刪除Route::group(['middleware' => ['web']], function() {線我可以訪問該頁面,但它給我的

未定義變量的錯誤:錯誤

這就是爲什麼網絡middelware是必需的,所以我有點卡住了。

控制器和視圖的工作。這只是我無法弄清楚的重定向。

感謝您的幫助!

+0

您的路線之前其他路線 – Veniamin

回答

2

您需要對您的AuthController進行更改,並將其放到您希望重定向到的位置。

然後,你需要在你擁有的每控制器補充一點:

public function __construct() { $this->middleware('auth'); } 
+0

試過welcome'頁面必須是'回報,但沒有任何結果。 – Nicolas

+0

這工作!可以簡要解釋它到底是什麼?謝謝! – Nicolas

+0

與每個構造函數一樣,無論何時使用控制器,該函數都會自動調用。這意味着您已經登錄,並且您可以使用該路線中的該方法。我爲我的糟糕的英語而努力,我希望你明白 –

0

你必須要像在資源/視圖auth.blade.php刀片模板。然後,你需要從你的控制器的觀點與像一回:

public function getLogin(){ 
     return view(
      "auth", 
      [ 
       'username' => username, 
       'password' => password 
      ] 
     ); 
}