Code Demon Code Demon - 1 month ago 7
PHP Question

use a controller inside a folder in the controllers folder

I'm trying to use a controller inside a folder in the controllers directory like

route

Route::get('/','site\HomeController@index');


but seem's does not work like it gives me this error


Class App\Http\Controllers\site\HomeController does not exist


Note: I have also a HomeController.php in the controllers folder. I'm trying to organize my controllers by putting them unto their specific folders.

Any help, ideas please?

Answer

You should use proper namespace, like:

namespace App\Http\Controllers\Site;

And add this line:

use App\Http\Controllers\Controller;

Then this route will work:

Route::get('/','Site\HomeController@index');