1

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.

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Lagbox thank you very much!!! It works now. I totally did not notice missing Controller use statement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.