Skip to content
Advertisement

laravel controller is not instantiable

Im calling my controller in routes.php:

JavaScript

In my controller is the method request:

JavaScript

Problem is, that im getting error:

JavaScript

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:

JavaScript

To:

JavaScript

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:

JavaScript

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