Target class does not exist in Laravel - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

Target class does not exist in Laravel
======================================

### [\#Laravel](https://rocketeersapp.com/knowledge/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](https://rocketeersapp.com/author/mark-van-eijk) on June 23, 2026 · 1 minute read

1. [About the error](#content-about-the-error)
2. [Why do I see this error](#content-why-do-i-see-this-error)
3. [Solution](#content-solution)
4. [Use the class-based route syntax](#content-use-the-class-based-route-syntax)
5. [Check the namespace](#content-check-the-namespace)
6. [Refresh the autoloader](#content-refresh-the-autoloader)

[\#](#content-about-the-error "Permalink")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.

[\#](#content-why-do-i-see-this-error "Permalink")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.

[\#](#content-solution "Permalink")Solution
-------------------------------------------

### [\#](#content-use-the-class-based-route-syntax "Permalink")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');

```

### [\#](#content-check-the-namespace "Permalink")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;`.

### [\#](#content-refresh-the-autoloader "Permalink")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](/clear-cache-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!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#Laravel](https://rocketeersapp.com/knowledge/laravel)

- [How to use different PHP versions with Laravel Valet](https://rocketeersapp.com/knowledge/different-php-versions-laravel-valet)
- [Disable cookies in Laravel](https://rocketeersapp.com/knowledge/disable-cookies-in-laravel)
- [Logging in Laravel](https://rocketeersapp.com/knowledge/laravel-logging)
- [How to check which Laravel version of your app is using](https://rocketeersapp.com/knowledge/check-laravel-version)
- [Disable CSRF in Laravel](https://rocketeersapp.com/knowledge/disable-csrf-in-laravel)
- [Creating an encrypted cookie value in Laravel](https://rocketeersapp.com/knowledge/creating-an-encrypted-cookie-value-in-laravel)

 [View all 19 articles →](https://rocketeersapp.com/knowledge/laravel)
