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.
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 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
- Check the namespace line and file path match
composer dump-autoload- Add the correct
usestatement
Detailed fix by platform
Laravel
composer dump-autoload -o && php artisan optimize:clear
How to diagnose
- Namespace — Matches path?
- Case — Same on disk?
- 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:
Similar errors
- 403 This action is unauthorized Laravel: Illuminate\Auth\Access\AuthorizationException: This action is unauthorized.
- Attempt to read property "x" on null Laravel/PHP 8: ErrorException: Attempt to read property "name" on null
- BadMethodCallException: Call to undefined method Laravel: BadMethodCallException: Call to undefined method App\Models\Post::whereTitle() / Illuminate\Database\Eloquent\Builder::foo()
Most viewed in Laravel
- MassAssignmentException Laravel: Illuminate\Database\Eloquent\MassAssignmentException: Add [x] to fillable property to allow mass assignment
- The GET method is not supported for route Laravel: The GET method is not supported for route x. Supported methods: POST (MethodNotAllowedHttpException)
- Route [login] not defined Laravel: Symfony\Component\Routing\Exception\RouteNotFoundException: Route [login] not defined
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 4 Nov 2026