Nick Audenaerde
Nick Audenaerde

Reputation: 1025

laravel can't find controller in subfolder

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?

Upvotes: 0

Views: 4233

Answers (2)

Tobias K.
Tobias K.

Reputation: 3092

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)

Upvotes: 1

ali
ali

Reputation: 862

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

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

 });

Upvotes: 2

Related Questions