类Illuminate \ Routing \ Route的对象无法转换为int

时间:2016-02-19 20:13:51

标签: php laravel

我有这样的路线:

Route::post('login', [
    'uses' => 'AuthController@postLogin',
    'before' => 'guest'
]);

但它不起作用我只得到错误:'类Illuminate \ Routing \ Route的对象无法转换为int'

我不知道我到底做错了什么。

我的路线:

Route::group(['middleware' => ['auth, guest']], function () { 
   Route::get('/', array('as' => 'home', 'uses' => 'HomeController@getIndex')); 
   Route::get('/login', array('as' => 'login', 'uses' => 'AuthController@getLogin')) - 
   Route::post('login', [ 'uses' => 'AuthController@postLogin', 'before' => 'guest', ]); 
}); 

AuthController

public function postLogin() { 

   $rules = array('username' => 'required', 'password' => 'required'); 
   $validator = Validator::make(Input::all(), $rules); 

   if ($validator->fails()) { 

      return Redirect::route('login')->withErrors($validator); 
   } 

   $auth = Auth::attempt(array( 'name' => Input::get('username'), 'password' => Input::get('password'), ), false); 

   if (!$auth) { 
      return Redirect::route('login')->withErrors(array( 'Invalid credentials were provided', )); 

   } 
   return Redirect::route('home'); 

}

1 个答案:

答案 0 :(得分:2)

我能够复制你得到的错误。

您的路线中有拼写错误。 (修复第一行的分号。)

改变这个:

Route::get('/login', array('as' => 'login', 'uses' => 'AuthController@getLogin'));

Route::post('login', [
    'uses' => 'AuthController@postLogin',
    'before' => 'guest'
]);

要:

Upload.bat