Skip to content
Advertisement

laravel controller is not instantiable

Im calling my controller in routes.php:

Route::get('request', 'Controller@request');

In my controller is the method request:

class Controller extends BaseController {

   public function request()
   {
        $number1 = int rand ( 10, 20 );
        $number2 = int rand ( 0, 10 );
        return View::make('request', array($number1, $number2));
   }
}

Problem is, that im getting error:

exception 'IlluminateContainerBindingResolutionException' with message 'Target [Controller] is not instantiable.'

I was browsing internet in order to find solution. A lot of simmilar errors are related to interfaces and I couldn’t find anything useful. I renamed my controller once, what caused some error, but I repaired it with “composer dump-autoload” command.

Advertisement

Answer

Change the controller class from:

class Controller extends BaseController {

To:

class ControllerController extends BaseController {

Why do this? Because Controller class already exists in Laravel (BaseController extends from Controller), so you probably want to name this to something else.

Also make sure the file is saved as ControllerController.php in the controllers dir.

Also your route should look like this:

Route::get('request', 'ControllerController@request');

I’ve tested this quickly on my local dev machine and it works.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement