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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35514151/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:16:07  来源:igfitidea点击:

Object of class Illuminate\Routing\Route could not be converted to int

phplaravel

提问by yakuzafu

I've got route like this:

我有这样的路线:

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

but it doesn't work and I got only error: 'Object of class Illuminate\Routing\Route could not be converted to int'

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

I don't know exactly what I'm doing wrong.

我不知道我做错了什么。

My routes:

我的路线:

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

}

采纳答案by Jilson Thomas

I was able to replicate the error you got.

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

You've a typo in your routes. (Fix the semicolon on the first line.)

你的路线有错别字。(修正第一行的分号。)

Change this:

改变这个:

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

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

To:

到:

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

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