Route类的对象无法转换为int

Route类的对象无法转换为int

我有这样的路线:

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

}

最佳答案

我能够复制您遇到的错误。

您的路线有错字。 (将分号固定在第一行。)

更改此:

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

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

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

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

关于php - Illuminate\Routing\Route类的对象无法转换为int,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35514151/

10-10 03:05