0
votes

I'm trying to put the HomeController in a folder called Front. This is Laravel 5.6

So the path to my controller is Controllers/Front/HomeController.php

namespace App\Http\Controllers\Front;

use Illuminate\Http\Request;

class HomeController extends Controller
    {

Then in my routes I have this:

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

As suggested in this Stackoverflow: Laravel Controller Subfolder routing I have tried to add the controller to the subfolder, then run composer dump-autoload yet it doesnt work.

Any suggestions?

2
You may have to run composer dumpautoload. If you moved the file and/or changed the namespace, that could be an issue in your composer.lock file. - Dimitri Mostrey

2 Answers

2
votes

you can add all route in group and make prefix for it

  Route::group(['namespace' => 'Front'], function () {
        Route::get('/', 'HomeController@index');

 });
1
votes

Either specify the prefix in the controller string: 'Front\HomeController@index' (https://laravel.com/docs/5.6/controllers#controllers-and-namespaces)

Or put your route in a group with the namespace: https://stackoverflow.com/a/51800675/7362396 (https://laravel.com/docs/5.6/routing#route-group-namespaces)