# Target class does not exist

The container looked for a class by the name in brackets and could not load it. Check the name, the file path, and stale autoload or route caches.

Message:

```text
Target class [ReportController] does not exist.
```

Exception:

```text
Illuminate\Contracts\Container\BindingResolutionException
```

## What it means

Laravel's service container was asked to build something by name: the controller of a route, a middleware, or a service. It found no binding under that name, so it tried to load a class with exactly that name, and the autoloader found none. The text in square brackets is the name it looked for, and it usually shows the mistake. Its sibling, `Target [App\Contracts\PaymentGateway] is not instantiable.`, is the same exception for the opposite case: the name was found, but it is an interface or abstract class the container cannot construct.

## Why it happens

- A controller named as a string without its namespace. `Route::get('/reports', 'ReportController@index')` fails with `Target class [ReportController] does not exist.`, because Laravel does not put `App\Http\Controllers` in front of it.
- A middleware alias that was never registered. `->middleware('subscribed')` without an alias gives `Target class [subscribed] does not exist.`
- A service that was never bound. `app('payments')` gives `Target class [payments] does not exist.`
- A file name that does not match the class. Composer's PSR-4 autoloader looks for `App\Http\Controllers\PaymentController` in `app/Http/Controllers/PaymentController.php`, so a file named `PaymentsController.php` is never found. Case counts on Linux: `Ordercontroller.php` works on a default macOS disk and fails on a case-sensitive file system, so the error can appear only after a deploy.
- A stale cache. An autoloader built with `--classmap-authoritative` before the class existed does not look on disk for new classes. A route cache made before you renamed a controller still points at the old name.
- For "not instantiable": an interface type-hinted somewhere with no binding to a class that implements it. In a constructor, the message names the class being built: `Target [App\Contracts\PaymentGateway] is not instantiable while building [App\Http\Controllers\CheckoutController].`

A wrong `namespace` line inside the file fails differently. PHP stops with the fatal error `Cannot redeclare class App\Http\Controller\InvoiceController (previously declared in ...)`, because Composer's autoloader includes the file again each time the class is looked for.

## How to fix it

Name controllers by class, so a missing import shows up in your editor:

```php
<?php

use App\Http\Controllers\ReportController;

Route::get('/reports', [ReportController::class, 'index']);
```

Register middleware aliases in `bootstrap/app.php`:

```php
<?php

use App\Http\Middleware\EnsureUserIsSubscribed;

return Application::configure(basePath: dirname(__DIR__))
    ->withMiddleware(function (Middleware $middleware): void {
        $middleware->alias([
            'subscribed' => EnsureUserIsSubscribed::class,
        ]);
    })
    ->create();
```

Bind a service in a service provider's `register` method before you resolve it by a string name, or resolve it by its class name.

For a file or namespace mismatch, rebuild the autoloader as an optimized class map. Composer then names every class it skips:

```bash
composer dump-autoload -o
```

```text
Class App\Http\Controllers\OrderController located in ./app/Http/Controllers/Ordercontroller.php does not comply with psr-4 autoloading standard (rule: App\ => ./app). Skipping.
```

Rename the file to match the class exactly, including case. On a case-insensitive disk Git does not notice a rename that only changes case, so use `git mv -f`.

For a stale route or config cache, clear it, and in your deploy run the cache commands after the new code and `composer install` are in place. `optimize:clear` does not touch Composer's class map, so for an authoritative class map run `composer dump-autoload` again with the same options:

```bash
php artisan optimize:clear
```

For "not instantiable", tell the container which class to build, in a service provider:

```php
<?php

$this->app->bind(PaymentGateway::class, StripeGateway::class);
```

Or put the binding on the interface itself:

```php
<?php

use Illuminate\Container\Attributes\Bind;

#[Bind(StripeGateway::class)]
interface PaymentGateway
{
}
```

## Find it in production

A visitor gets a 500 "Server Error" page with `APP_DEBUG=false`, and `storage/logs/laravel.log` has the `BindingResolutionException` with its stack trace. Because Laravel reports it, [Ranetrace error monitoring](/features/error-monitoring) records it with the stack trace and the request it happened on. When the error starts right after a deploy, suspect file name case or a stale cache first.

Reproduced on PHP 8.5, Laravel 13.45, 5 December 2026.

Read more: https://laravel.com/docs/container

## Related

### Terms

- [Service container in Laravel](https://ranetrace.com/glossary/service-container-in-laravel.md)
- [Service providers in Laravel](https://ranetrace.com/glossary/service-providers-in-laravel.md)
- [Middleware in Laravel](https://ranetrace.com/glossary/middleware-in-laravel.md)

### Other errors

- [Route \[name\] not defined](https://ranetrace.com/error-guides/laravel-route-not-defined.md)
- [Class "Redis" not found](https://ranetrace.com/error-guides/laravel-class-redis-not-found.md)
- [Call to undefined method](https://ranetrace.com/error-guides/laravel-call-to-undefined-method.md)

Read this guide in a browser: https://ranetrace.com/error-guides/laravel-target-class-does-not-exist
