Back to Blog
Bug Fixes•1 min read

Fix Laravel 'Target class [Controller] does not exist'

Scaleup Infotech Team
Scaleup Infotech Team

Custom Software & Business Automation

LaravelRoutingNamespaces

In this guide

A simple guide to this issue: Laravel 'Target class [Controller] does not exist'. Learn why it happens, what to check first, and how to fix it.

Since Laravel 8 removed the default controller namespace prefix, string-based route definitions are the number one cause of this error. Here is the modern, reliable way to declare routes.

The Error

Illuminate\Contracts\Container\BindingResolutionException: Target class [App\Http\Controllers\UserController] does not exist.

Fix: Use the Class-Based Route Syntax

php
// ❌ Old string syntax (relies on a namespace prefix that no longer exists)
Route::get('/users', 'UserController@index');

// ✅ Import the class and reference it
use App\Http\Controllers\UserController;

Route::get('/users', [UserController::class, 'index']);

Check the Namespace Matches the Path

A controller in app/Http/Controllers/Admin/ must declare namespace App\Http\Controllers\Admin;. A mismatch here produces the same error.

Rebuild the Autoloader

bash
composer dump-autoload
php artisan optimize:clear

Typo Check

Class names are case-sensitive on Linux servers. Usercontroller vs UserController will work on macOS and fail in production.

Share this article:

Keep Reading

Ready to implement these ideas?

Discuss Your Project