Target class does not exist 🐘 PHP

Laravel: Target class [App\Http\Controllers\X] does not exist.

Laravel’s container couldn’t find the controller or class named in a route or binding.

Seen on: PHP

Meaning

Since Laravel 8 route strings aren’t automatically prefixed with the controller namespace. Typos, wrong namespaces, missing use statements and stale autoload maps all cause it.

Common causes

  • Route uses 'UserController@index' string syntax without namespace (Laravel 8+)
  • Class/namespace typo
  • File name case differs from class name
  • Autoload not regenerated

⚡ Quick fix

  1. Use the class syntax: [UserController::class, 'index'] with a use import
  2. Check namespace and file name case
  3. composer dump-autoload

Detailed fix by platform

PHP

  1. Route::get('/users', [\App\Http\Controllers\UserController::class, 'index']);

How to diagnose

  1. Class — Exact class string in the message
  2. File — Does it exist at the PSR-4 path?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.