Class "App\Models\X" not found Laravel Origin: Application & API Last updated 4 Nov 2026

Laravel: Error: Class "App\Models\Post" not found

PHP can't find the class you referenced — a missing import, wrong namespace or file name, or a stale autoloader.

Exact message you may see Class "App\Models\Post" not foundError: Class "App\Models\User" not foundClass 'App\Post' not foundClass "App\Http\Controllers\HomeController" does not existIlluminate\Contracts\Container\BindingResolutionException: Target class does not exist
Seen on: Laravel PHP

Meaning

Class names, namespaces and file paths must agree (PSR-4: App\Models\Post lives in app/Models/Post.php). On Linux file names are case-sensitive, which breaks code written on macOS/Windows. After adding classes or moving files, run composer dump-autoload.

Common causes

  • Missing use App\Models\Post; or wrong namespace in the file
  • File name case differs from the class name (Linux)
  • Class moved without updating namespaces
  • Autoloader not regenerated
  • Model in App\ after upgrading to Laravel 8+ (App\Models)

⚡ Quick fix

  1. Check the namespace line and file path match
  2. composer dump-autoload
  3. Add the correct use statement

Detailed fix by platform

Laravel

  1. composer dump-autoload -o && php artisan optimize:clear

How to diagnose

  1. Namespace — Matches path?
  2. Case — Same on disk?
  3. Autoload — Regenerated?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

403 This action is unauthorized — Laravel: Illuminate\Auth\Access\AuthorizationException: This action is unauthorized. (Laravel)403 This action is un…Attempt to read property "x" on null — Laravel/PHP 8: ErrorException: Attempt to read property "name" on null (Laravel)Attempt to read prope…BadMethodCallException: Call to undefined method — Laravel: BadMethodCallException: Call to undefined method App\Models\Post::whereTitle() / Illuminate\Database\Eloquent\Builder::foo() (Laravel)BadMethodCallExceptio…Command "x" is not defined — Laravel: Symfony\Component\Console\Exception\CommandNotFoundException: Command "make:livewire" is not defined. Did you mean one of these? (Laravel)Command "x" is not de…InvalidArgumentException: View [x] not found — Laravel: InvalidArgumentException: View [posts.index] not found. (Laravel)InvalidArgumentExcept…Laravel: Allowed memory size exhausted (request) — Laravel/PHP: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in vendor/laravel/framework (Laravel)Laravel: Allowed memo…Livewire: Unable to find component — Laravel Livewire: Livewire\Exceptions\ComponentNotFoundException: Unable to find component: [admin.users] (Laravel)Livewire: Unable to f…Target class does not exist — Laravel: Target class [App\Http\Controllers\X] does not exist. (PHP)Target class does not…Class "Ap…

Explore the map of this error Full error map →

🧠 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.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.