php Errors

20 error patterns

php4 fixes

Undefined variable used

Undefined variable.*\$

  • Initialize the variable before use
  • Check for typos in the variable name
php4 fixes

PHP class not found

Class ['"].*['"] not found

  • Run composer dump-autoload to regenerate autoload files
  • Check namespace matches directory structure (PSR-4)
php3 fixes

Database table does not exist

SQLSTATE\[42S02\].*Table.*doesn't exist

  • Run php artisan migrate to create the table
  • Check table name in migration matches what the model expects
php4 fixes

Duplicate key constraint violation

SQLSTATE\[23000\].*Integrity constraint violation.*Duplicate entry

  • Use firstOrCreate() or updateOrCreate() instead of create()
  • Add unique validation rule before saving
php3 fixes

Array offset undefined or null access

Undefined.*offset|Trying to access array offset on.*null

  • Check array key exists: isset($arr['key']) or array_key_exists()
  • Use null coalescing: $arr['key'] ?? 'default'
php4 fixes

Blade view template not found

View \[.*\] not found

  • Check the view path matches file location: resources/views/path/file.blade.php
  • Verify dot notation matches directory separators
php4 fixes

CSRF token validation failed

CSRF token mismatch

  • Add @csrf directive inside your form
  • For AJAX: include X-CSRF-TOKEN header from meta tag
php3 fixes

Session not available in request

Session store not set on request

  • Ensure the route is within the 'web' middleware group
  • Check session driver configuration in .env and config/session.php
php4 fixes

Laravel container cannot resolve class

Target class \[.*\] does not exist

  • Check controller namespace in route file (Laravel 8+ requires full namespace)
  • Register the binding in a Service Provider
php4 fixes

PHP max execution time exceeded

Maximum execution time of.*seconds exceeded

  • Optimize the slow operation (add database indexes, reduce loops)
  • Increase max_execution_time in php.ini for legitimate long operations
php4 fixes

PHP memory limit exhausted

Allowed memory size of.*bytes exhausted

  • Use chunk() or cursor() for large Eloquent queries
  • Increase memory_limit in php.ini if the operation legitimately needs more
php3 fixes

Call to undefined static method

Call to undefined method.*::

  • Check the class actually has this static method
  • Verify you're not calling an instance method statically
php4 fixes

Database column not found

SQLSTATE\[42S22\].*Column not found

  • Create a migration to add the column: php artisan make:migration
  • Check for typos in column name
php3 fixes

HTTP method not supported for route

The (GET|POST|PUT|DELETE) method is not supported for (route|this route)

  • Check your form method matches the route definition
  • Add @method('PUT') or @method('DELETE') for spoofed methods
php4 fixes

Accessing undefined property on class

ErrorException.*Undefined property.*::\$

  • Declare the property in the class definition
  • Check for typos in the property name
php4 fixes

Class not found during dependency injection

ReflectionException.*Class.*does not exist

  • Run composer dump-autoload to regenerate class map
  • Verify the class namespace and file path follow PSR-4
php4 fixes

File write permission denied

file_put_contents.*Permission denied

  • Fix permissions: chmod -R 775 storage bootstrap/cache
  • Set correct ownership: chown -R www-data:www-data storage
php4 fixes

Composer dependency resolution failed

Your requirements could not be resolved to an installable set of packages

  • Run composer update --with-all-dependencies to resolve together
  • Check for PHP version requirements in failed packages
php4 fixes

Database connection refused

Illuminate\\Database\\QueryException.*SQLSTATE\[HY000\].*Connection refused

  • Verify database service is running
  • Check .env DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD
php4 fixes

Required field validation failure

The.*field is required|validation\.required

  • Ensure the form input name matches the validation rule key
  • Check that the field is included in the request (not empty/missing)