Back to Error Center

Target class does not exist

Error Message

Target class [App\Http\Controllers\PostController] does not exist.

Cause

The controller class referenced in a route doesn't exist or the namespace is wrong in the route file.

Solution

Create the controller with make:controller. Verify the full namespace path in the route file. Run composer dump-autoload if the class was recently created.

Code Example

Fix
// Check the route file
use App\Http\Controllers\PostController; // Verify this path

Route::resource('posts', PostController::class);

// Create the controller if missing
php artisan make:controller PostController --resource

Debugging Steps

  1. Verify the class exists at the expected namespace
  2. Run composer dump-autoload
  3. Check for typos in the route file import
  4. Verify the controller file is in the correct directory

Prevention

Use IDE auto-import for classes. Always run composer dump-autoload after creating new classes. Follow Laravel's directory conventions.