Laravel 8 issue with controller inside subfolder

  controller, laravel, namespaces, php

I have laravel 8 project and I am facing issue with controller which is in subfolder.

I have DashboardController located in /app/Http/Controllers/Dashboard. In my web.php I have:

use AppHttpControllersDashboardDashboardController;
Route::get('dashboard', [DashboardController::class, 'dashboardView']);

DashboardController has this namespace:

namespace AppHttpControllersDashboard;

I have tried uncomment $namespace variable in RouteServiceProvider.php. Also I have added:

 ->namespace($this->namespace); 

in boot() method. But with no luck. I got this error:

Class 'AppHttpControllersDashboardController' not found"

When I have DashboardController in laravel controller folder, everything works well. Also interesting is LoginController. It is in Auth subfolder (Controllers/Auth) and this controller works from subfolder.

Reason why I want to move controller into subfolder(s) is better organisation of files.

Is anybody here, who can help me figure out this issue? Thank you very much in advance.

Source: Laravel

Leave a Reply