1
votes

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?

2

2 Answers

2
votes

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

The namespace of the class HomeController should be as:

namespace App\Http\Controllers\Site;

And in your route file you can use it as:

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

Remember to add following line of code in HomeController class as:

use App\Http\Controllers\Controller;