# Error guides

Common PHP and Laravel errors: what each one means, why it happens and how to fix it.

## Laravel

- [419 Page Expired](https://ranetrace.com/error-guides/laravel-419-page-expired.md) - Laravel refused a form or request because its CSRF token was missing or did not match the session. Send the token and make sure the session cookie comes back.
- [429 Too Many Requests](https://ranetrace.com/error-guides/laravel-429-too-many-requests.md) - A throttle middleware counted too many requests for one key. Key the limiter on the user or the real IP, trust your proxy, and honour Retry-After.
- [Add \[x\] to fillable property to allow mass assignment](https://ranetrace.com/error-guides/laravel-mass-assignment-fillable.md) - Eloquent refused to fill a model from an array because the attribute is not mass assignable. Declare the fillable attributes and pass only validated input.
- [Call to undefined method](https://ranetrace.com/error-guides/laravel-call-to-undefined-method.md) - You called a method the object does not have: a typo, a missing relation or trait, or a model method on a collection. The class in the message says where.
- [Class "Redis" not found](https://ranetrace.com/error-guides/laravel-class-redis-not-found.md) - Laravel uses the phpredis extension by default, and the PHP running your code has not loaded it. Install and enable the extension, or switch to Predis.
- [Job has been attempted too many times](https://ranetrace.com/error-guides/laravel-job-attempted-too-many-times.md) - A worker picked up a job that had used all its tries, often because an earlier attempt was cut off. Keep retry_after longer than your longest job.
- [laravel.log could not be opened in append mode: Permission denied](https://ranetrace.com/error-guides/laravel-log-file-permission-denied.md) - The user PHP runs as cannot write to storage/logs/laravel.log. Fix the owner and group of storage and bootstrap/cache, never chmod 777.
- [No application encryption key has been specified](https://ranetrace.com/error-guides/laravel-no-application-encryption-key.md) - Laravel needs APP_KEY to encrypt cookies and data, and found it empty. Check .env and the cached config first, and generate a key only when there is none.
- [No query results for model](https://ranetrace.com/error-guides/laravel-no-query-results-for-model.md) - A findOrFail, firstOrFail or route model binding found no row, and Laravel answered 404. Check the id, soft deletes, scoped bindings and queued jobs.
- [Route \[name\] not defined](https://ranetrace.com/error-guides/laravel-route-not-defined.md) - Your code asked for the URL of a named route that the router does not have. Fix the name, add it with ->name(), or rebuild a stale route cache.
- [SQLSTATE\[42S02\]: Base table or view not found: 1146 Table doesn't exist](https://ranetrace.com/error-guides/laravel-sqlstate-1146-table-not-found.md) - MySQL has no table by the name the query used, in the database it named. Run the migrations, check the connection, or set the table name on the model.
- [SQLSTATE\[42S22\]: Column not found: 1054 Unknown column](https://ranetrace.com/error-guides/laravel-sqlstate-1054-unknown-column.md) - The query names a column the table does not have. Run the pending migration, fix the name or table prefix, and never sort by a raw request value.
- [SQLSTATE\[23000\]: Integrity constraint violation: 1062 Duplicate entry](https://ranetrace.com/error-guides/laravel-sqlstate-1062-duplicate-entry.md) - MySQL refused an insert because the value already exists in a unique column. Validate first, use firstOrCreate or upsert, and catch the exception for races.
- [SQLSTATE\[23000\]: Integrity constraint violation: 1452 Cannot add or update a child row](https://ranetrace.com/error-guides/laravel-sqlstate-1452-foreign-key-constraint.md) - MySQL refused a row whose foreign key points at a parent row that does not exist. Validate the id with exists, create parents first, and clean up orphans.
- [SQLSTATE\[HY000\]: General error: 1364 Field doesn't have a default value](https://ranetrace.com/error-guides/laravel-sqlstate-1364-field-no-default.md) - An insert left out a NOT NULL column that has no default. Pass the value, check that the model lets it through, or make the column nullable or defaulted.
- [SQLSTATE\[HY000\] \[1045\] Access denied for user](https://ranetrace.com/error-guides/laravel-sqlstate-1045-access-denied.md) - MySQL refused the user, password or host Laravel sent. Test the login with the mysql client, quote the password in .env and rebuild the config cache.
- [SQLSTATE\[HY000\] \[2002\] Connection refused](https://ranetrace.com/error-guides/laravel-sqlstate-2002-connection-refused.md) - PHP could not open a connection to MySQL at the host and port Laravel used. Start the server or correct DB_HOST and DB_PORT, then clear the config cache.
- [Target class does not exist](https://ranetrace.com/error-guides/laravel-target-class-does-not-exist.md) - The container looked for a class by the name in brackets and could not load it. Check the name, the file path, and stale autoload or route caches.
- [The GET method is not supported for route](https://ranetrace.com/error-guides/laravel-method-not-supported-for-route.md) - The URL matches a route, but not for the HTTP method the request used. Usually a GET reached a POST-only route; Laravel answers 405.
- [The POST data is too large](https://ranetrace.com/error-guides/laravel-post-data-too-large.md) - The request body is larger than PHP's post_max_size, so Laravel answers 413. Raise post_max_size, upload_max_filesize and the web server limit together.
- [View \[name\] not found](https://ranetrace.com/error-guides/laravel-view-not-found.md) - Laravel found no template file for the view name. Check that dots match folders, the .blade.php ending, the exact case, and the cached config.
- [Vite manifest not found at: public/build/manifest.json](https://ranetrace.com/error-guides/laravel-vite-manifest-not-found.md) - The @vite directive needs public/build/manifest.json, which only exists after npm run build. Run the build on the server or in your deploy.

## PHP

- [Allowed memory size exhausted](https://ranetrace.com/error-guides/php-allowed-memory-size-exhausted.md) - A fatal error: the script asked for more memory than memory_limit allows. Read the data in smaller pieces first, and raise the limit only after that.
- [Attempt to read property on null](https://ranetrace.com/error-guides/php-attempt-to-read-property-on-null.md) - You read a property of null; its sibling "Call to a member function x() on null" calls a method on null. Decide what null means there, then handle it.
- [Call to a member function on null](https://ranetrace.com/error-guides/php-call-to-a-member-function-on-null.md) - You called a method on a variable that holds null. Find where the null came from, then fail early with findOrFail or auth, or allow it with ?->.
- [Maximum execution time exceeded](https://ranetrace.com/error-guides/php-maximum-execution-time-exceeded.md) - A fatal error: the script ran longer than max_execution_time. Find the slow part and move long work to a queue before you raise the limit.
- [Trying to access array offset on null](https://ranetrace.com/error-guides/php-trying-to-access-array-offset-on-null.md) - You used [] on null, often after a failed json_decode or a missing config key. Check the source of the value, or read it with data_get.
- [Undefined array key](https://ranetrace.com/error-guides/php-undefined-array-key.md) - You read an array key that is not set. PHP 8 warns and Laravel throws an ErrorException. Read it with ??, Arr::get or validated input.

The same guides in a browser: https://ranetrace.com/error-guides
