Illuminate\Contracts\Container\BindingResolutionException: Target class [X] does not exist
ID: php/laravel-container-binding-resolution
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 83 | active | — | — | — |
Root Cause
The Laravel service container cannot resolve a binding because the target class doesn't exist, wasn't registered, or auto-discovery failed. Common after upgrading Laravel 8+ which removed default namespace prefix from RouteServiceProvider.
genericWorkarounds
-
95% success Use fully qualified class names in route definitions
In routes/web.php, change: Route::get('/users', 'UserController@index'); To: use App\Http\Controllers\UserController; Route::get('/users', [UserController::class, 'index']);Sources: https://laravel.com/docs/10.x/controllers#basic-controllers
-
93% success Register the binding explicitly in a ServiceProvider
In AppServiceProvider::register(): $this->app->bind(MyInterface::class, MyImplementation::class); // Or for singletons: $this->app->singleton(MyService::class, function ($app) { return new MyService($app->make(Dependency::class)); }); -
80% success Clear all cached configs, routes, and services
php artisan config:clear && php artisan route:clear && php artisan cache:clear && composer dump-autoload
Dead Ends
Common approaches that don't work:
-
Adding the full namespace prefix back to RouteServiceProvider::$namespace
60% fail
Laravel 8+ intentionally removed the default namespace prefix to support PHP 8 named arguments and better IDE support. Re-adding it creates subtle routing issues with resource controllers and invokable controllers.
-
Running composer dump-autoload repeatedly without checking the actual class path
70% fail
dump-autoload regenerates the autoloader map, but if the class file doesn't exist or the namespace doesn't match the directory structure (PSR-4), re-dumping won't help.