Reputation: 47
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 App\Http\Controllers\Dashboard\DashboardController;
Route::get('dashboard', [DashboardController::class, 'dashboardView']);
DashboardController has this namespace:
namespace App\Http\Controllers\Dashboard;
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 'App\Http\Controllers\Dashboard\Controller' 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.
Upvotes: 1
Views: 2387
Reputation: 50481
In that class file you are referencing Controller
; most likely extends Controller
on the class definition. There is no class named Controller
in that namespace you have declared, App\Http\Controllers\Dashboard
. You are most likely trying to reference App\Http\Controllers\Controller
which means you will need a use
statement for that or referencing it by its FQCN, Fully Qualified Class Name.
Upvotes: 4