PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, December 29, 2021

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

 December 29, 2021     laravel, php     No comments   

Issue

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

}

Solution

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


Answered By - Jilson Thomas
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing