Laravel: Controller does not exist

强颜欢笑 提交于 2019-12-03 08:30:59

Did you add autoload classmap to composer.json file? Open your composer.json file and add

"autoload": {
        "classmap": [
            "app/controllers/admin",
        ]
    }

if you add folders inside controllers, you need to add it to composer.json file. Then run

composer dumpautoload

OR ALTERNATIVE

go to app/start/global.php and add

ClassLoader::addDirectories(array(
    app_path().'/controllers/admin',
));
Balasubramanian

We need to create controller via command line.

php artisan make:controller nameController --plain.

Before Laravel 5, make namespace is not available. Instead, this works

php artisan controller:make nameController

Execute your command inside your project directory and then create your function.

In my case, in the top of my controller code i add this line :

namespace App\Http\Controllers\CustomFolder\ControllerClassName;

and my problem is solved

Don't forget to do:

php artisan route:clear

In my case this was the solution when I got this error after making a route code change.

I think your problem has already been fixed. But this is what did.

Structure

Http
  .Auth
  .CustomControllerFolder
    -> CustomController.php

to get this working in your route file make sure you use the correct name space for eg:

  Route::group(['namespace'=>'CustomControllerFolder','prefix'=>'prefix'],
      function() {

   //define your route here
}

Also dont forget to use namespace App\Http\Controllers\CustomControllerFolder in your controller.

That should fix the issue.

Thanks

I just had this issue because I renamed a file from EmployeeRequestContoller to EmployeeRequestsContoller, but when I renamed it I missed the .php extension!

When I reran php artisan make:controller EmployeeRequestsContoller just to be sure I wasn't going crazy and the file showed up I could clearly see the mistake:

/EmployeeRequestsContoller
/EmployeeRequestsContoller.php

Make sure you have the extension if you've renamed!

Sometimes we are missing namespace App\Http\Controllers; on top of our controller code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!