0

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?

Nick Audenaerde
  • 967
  • 2
  • 14
  • 33
  • 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 Aug 11 '18 at 15:10

2 Answers2

2

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

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

 });
ali
  • 832
  • 6
  • 11
1

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)

Tobias K.
  • 2,997
  • 2
  • 12
  • 29
  • In another project i have there was no need to add the Front\ in the routes, also laravel 5.6 – Nick Audenaerde Aug 11 '18 at 14:32
  • Maybe there you had the namespace prefix specified in a route group? That is also a viable option. See https://laravel.com/docs/5.6/routing#route-group-namespaces – Tobias K. Aug 11 '18 at 14:34