2013-06-05 129 views
1

當我在laravel運行工匠路線4Laravel路由工匠

auth/login/{v1}/{v2}/{v3}/{v4}/{v5} 

這是正常的或者是有什麼錯。我的路線工作只是想知道是否可能有錯誤或什麼。以下是我的身份驗證路由。我正在使用安靜的路由進行身份驗證。

Route::controller('auth','AuthController'); 

Route::get('AuthController/login', array('as' => 'login', 'uses' => '[email protected]')); 
Route::get('auth/logout', array('as' => 'logout', 'uses' => '[email protected]')); 
Route::post('auth/login', array('uses' => '[email protected]')); 

回答

0

這是預期。當你註冊控制器Route::controller()控制器檢查員adds the URI wildcards。請看下面的例子:

Route::controller('user', 'UserController'); 

你可能會再有這樣的方法對你UserController

public function getProfile($username) 
{ 
    $user = User::where('username', $username)->first(); 

    return View::make('profile')->with('user', $user); 
} 

然後,您可以打的方法,通過將localhost/yourapp/user/profile/jason

在堅果殼它允許你傳遞額外的參數給一個方法。對我來說,這是一個非常古老的學校,因爲它看起來好像localhost/yourapp/user/jason/profile,在這種情況下,您需要使用路線來映射控制器方法。

0

我建議你2點改進:

1 - 跟上的URI

標準你不需要在這種情況下路線::控制器。爲了十個分量具有相同結構的所有路由我會做:

Route::group(array('prefix'=>'auth,function(){ //make all auth routes starting by auth 
    Route::get('getLogin', array('as' => 'getLogin', 'uses' => '[email protected]')); 
    Route::get('getLogin', array('as' => 'logout', 'uses' => '[email protected]')); 
    Route::post('postLogin', array('as' => 'postLogin', 'uses' => '[email protected]')); 
}); 

這是沒有必要使用組,但如果你的應用程序的增長可能會更好。如果沒有組代碼將是:

Route::get('auth/getLogin', array('as' => 'getLogin', 'uses' => '[email protected]')); 
Route::get('auth/getLogin', array('as' => 'logout', 'uses' => '[email protected]')); 
Route::post('auth/postLogin', array('as' => 'postLogin', 'uses' => '[email protected]')); 

2 - 保護您的郵路

對於每一個崗位,並把要求,我們已經阻止CSRF攻擊是這樣的:

Route::post('postLogin',array('before' => 'csrf','uses'=>[email protected])); 
+0

感謝你的幫助。我想給這兩個檢查,但只允許一個,我不想停止使用Route :: controller註冊寧靜的路線。 –

+0

在這種情況下,您可以使用'Resources'如下: Route :: resource('users','UsersControllers'); 有了這個,你已經爲用戶提供了完整的控制器。 – Joss