Error guides
Common PHP and Laravel errors: what each one means, why it happens and how to fix it.
Laravel
- 419 Page Expired 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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.
Start monitoring today
Websites go down and code throws errors. Ranetrace tells you when it happens to yours, why it matters and what to do next.