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'
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');
}
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'
]);
Also this error can happen sometimes if you use response()
if you use it without any parameter, in that case using it with a empty string parameter will save you, like: response('')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With