Error Center
Common Laravel errors and their solutions.
Class 'App\Models\X' not found
Class "App\Models\User" not found
Add the correct import statement at the top of the file: use App\Models\User;. If the model doesn\'t exist, create it with php artisan make:model.
Undefined property
Undefined property: App\Models\User::$nonexistent_field
Verify the column exists in the migration/schema. If it\'s a computed attribute, create an accessor method. Check the $fillable array if you\'re creat...
Mass assignment vulnerability
MassAssignmentException: Add [name] to fillable property
Add the field to the $fillable array in the model, or use the forceCreate/forceUpdate methods (not recommended). Ensure you only make fields fillable...
SQLSTATE connection refused
SQLSTATE[HY000] [2002] Connection refused
Start the database server. Check DB_HOST and DB_PORT in .env. For MySQL, ensure the service is running: sudo systemctl status mysql. For SQLite, ensur...
SQLSTATE table not found
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'database.posts' doesn't exist
Run php artisan migrate to create the tables. Check the table name in the migration and ensure it matches. If using a custom table name, set it in the...
SQLSTATE column not found
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'posts.nonexistent' in 'field list'
Create a new migration to add the missing column. Run php artisan migrate. Verify the column name in the model and query.
Target class does not exist
Target class [App\Http\Controllers\PostController] does not exist.
Create the controller with make:controller. Verify the full namespace path in the route file. Run composer dump-autoload if the class was recently cre...
Route [X] not defined
Route [posts.show] not defined
Run php artisan route:list to see all defined routes. Check the route definition and name. Ensure route files are loaded.
419 Page Expired
419 Page Expired
Add @csrf to your Blade form. For AJAX, include the X-CSRF-TOKEN header. Check session configuration and lifetime. Verify the CSRF token meta tag exis...
403 Forbidden
403 This action is unauthorized.
Check the authorization logic in policies/gates. Ensure the user has the required role/permission. Verify middleware in route definitions.
404 Not Found
404 NOT_FOUND
Check the URL for typos. Run php artisan route:list. If using route model binding, ensure the record exists. Check for soft-deleted models.
405 Method Not Allowed
405 METHOD_NOT_ALLOWED
Check the route definition for the correct HTTP method. Use the right form method in HTML (@method for PUT/DELETE). Verify the AJAX request method.
422 Validation Error
422 The given data was invalid.
Check the validation errors in the response. Review the rules in the Form Request. Ensure all required fields are present and valid.
500 Server Error
500 SERVER_ERROR
Check storage/logs/laravel.log for the actual error. Enable APP_DEBUG=true in development to see detailed errors. Check the stack trace for the root c...
CORS error
Access to XMLHttpRequest blocked by CORS policy: No Access-Control-Allow-Origin header
Configure CORS in config/cors.php. Add the frontend\'s domain to allowed_origins. For local development, add http://localhost:3000 or your dev server...
Method Illuminate\View\View::render does not exist
BadMethodCallException: Method Illuminate\View\View::render does not exist
Use @include to embed views, Blade components, or return the view from the controller. Don\'t call render() on View objects directly.
Type error / Argument must be of type
TypeError: App\Http\Controllers\PostController::show(): Argument #1 ($post) must be of type App\Models\Post, string given
Verify the type hint matches the expected parameter. Ensure route model binding is properly configured. Check the method signature against how it\'s c...
TokenMismatchException
Symfony\Component\HttpKernel\Exception\TokenMismatchException
Ensure @csrf is in every form. For SPAs, send the X-CSRF-TOKEN header. Clear browser cache and cookies. Check session configuration.
Session store not set on request
RuntimeException: Session store not set on request.
Ensure the web middleware is applied to routes that need sessions. Configure SESSION_DRIVER in .env. For API routes, use token-based auth instead.
Invalid argument supplied for foreach
Warning: Invalid argument supplied for foreach()
Ensure the variable is an array/collection before iterating. Use null coalescing or conditional checks. Eloquent methods return collections, query bui...