Knowledge

Target class does not exist in Laravel

#Laravel

This error means Laravel cannot resolve a controller or class you referenced in a route or container binding. Almost always a namespace, typo or autoload issue.

Published by Mark van Eijk on June 23, 2026 · 1 minute read

  1. About the error
  2. Why do I see this error
  3. Solution
  4. Use the class-based route syntax
  5. Check the namespace
  6. Refresh the autoloader

About the error

The message looks like:

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

Laravel's service container tried to instantiate a class by its name and couldn't find it.

Why do I see this error

There are a few usual suspects:

  • A typo in the controller name in your route definition.
  • A missing or wrong namespace at the top of the controller file.
  • You're using the string controller syntax on Laravel 8+, where the default namespace prefix was removed.
  • The autoloader hasn't picked up a newly created class.

Solution

Use the class-based route syntax

Since Laravel 8 the recommended way to reference a controller is by importing it and using its ::class constant, not a string:

use App\Http\Controllers\UserController;

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

This catches typos at compile time and resolves the namespace for you. The old string form relied on a namespace prefix that no longer exists by default:

// Fragile, the App\Http\Controllers prefix is no longer applied automatically
Route::get('/users', 'UserController@index');

Check the namespace

Open the controller and confirm its namespace matches its folder:

namespace App\Http\Controllers;

class UserController extends Controller
{
    // ...
}

A file in app/Http/Controllers/Admin/ must declare namespace App\Http\Controllers\Admin;.

Refresh the autoloader

If the class genuinely exists and the namespace is right, regenerate Composer's autoload map and clear caches:

composer dump-autoload
php artisan optimize:clear

See clearing the cache in Laravel for what gets cleared.

Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

Related articles

How to use different PHP versions with Laravel Valet

This error means Laravel cannot resolve a controller or class you referenced in a route or container binding. Almost always a namespace, typo or autoload issue.

Read more →

Disable cookies in Laravel

This error means Laravel cannot resolve a controller or class you referenced in a route or container binding. Almost always a namespace, typo or autoload issue.

Read more →