Fix this error
Laravel: Target class [Controller] does not exist
Dasun Kalupahana 194 views
The error
Error
Target class [UserController] does not exist.
Why it happens
Since Laravel 8, routes are not prefixed with the App\Http\Controllers namespace any more. A route written as 'UserController@index' (a string) can't be found. A typo in the class or namespace, or a missing use line, gives the same error.
How to fix it
- Import the controller at the top of
routes/web.phpand use the array syntax. - Check that the file name, class name and namespace match exactly (Linux is case-sensitive).
- Run
composer dump-autoloadif you moved or renamed the class.
use App\Http\Controllers\UserController;
Route::get('/users', [UserController::class, 'index']);
Learn more on the blog
PostgreSQL vs MySQL Performance: Real Benchmarks Compared
Last updated: 7 November 2026. See the update log at the end."Which...
How to Detect and Fix PHP Memory Leaks
Last updated: 5 November 2026. See the update log at the end.In...
Docker Build Too Slow? 10 Ways to Speed It Up
A slow Docker build usually has one of a few causes: you...