Skip to content

PHP and Laravel checklist

Copy this list into a pull request, design review or project kickoff and tick what applies. Rules are grouped by level and sorted by score (criteria). Each links to the file that explains it and cites its sources. Automatable names tools that can check the rule in CI (see the file's "How to enforce" section).

Also apply the general checklist.

This file is generated by python3 scripts/rank.py fix from the guidelines. Don't edit it by hand.

  • LARAVEL-1 (9) Never commit the .env file: commit .env.example with placeholder values, and supply the real values as environment variables on the server or in an encrypted environment file (php artisan env:encrypt). (specific/laravel) Automatable: GitHub secret scanning push protection.
  • LARAVEL-2 (9) In production, set APP_DEBUG to false and point the web server's document root at the public directory. (specific/laravel) Automatable: Semgrep Laravel rules.
  • LARAVEL-4 (9) Authorize every action: write the rules for each model in a policy and the other rules in gates, and check them in each controller action, in the Form Request's authorize() method, or with the can middleware. (specific/laravel)
  • LARAVEL-5 (9) Output data with Blade's escaped {{ }} syntax, use {!! !!} only for HTML you trust, never for content that users supplied, and pass data to JavaScript with Js::from(). (specific/laravel) Automatable: Psalm Laravel plugin, security analysis.
  • LARAVEL-6 (9) Pass values to raw SQL only as bindings, with ? or named placeholders, in DB::select(), whereRaw(), orderByRaw() and the other raw methods, and never let user input choose column names, including orderBy columns. (specific/laravel) Automatable: Psalm Laravel plugin, security analysis.
  • LARAVEL-7 (8) Validate every request with a Form Request or the validator, pass only the validated data ($request->validated() or safe()) to create(), fill() and update(), and declare each model's mass-assignable attributes with the Fillable attribute (the $fillable property before Laravel 13) instead of unguarding the model. (specific/laravel) Automatable: Semgrep Laravel rules.
  • LARAVEL-10 (8) Change the schema only through migrations in database/migrations, run them in each deployment with php artisan migrate --force, and add --isolated when several servers deploy at once. (specific/laravel)
  • LARAVEL-16 (8) Run a Laravel release that still receives security fixes, on a PHP branch that is still supported, and plan each upgrade before the support ends. (specific/laravel) Automatable: composer audit.
  • LARAVEL-3 (7) Run php artisan optimize in every deployment, to cache the configuration, events, routes and views; call env() only in the files in config/; and restart queue workers and other long-running processes after deploying, for example with php artisan reload. (specific/laravel) Automatable: Larastan rules.
  • LARAVEL-8 (7) Validate the type and size of every upload with the File rule, for example File::types([...])->max('10mb') or File::image(), and store it under a generated name with store() or hashName(), never a name built from getClientOriginalName(), getClientOriginalExtension() or other user input. (specific/laravel) Automatable: Psalm Laravel plugin, security analysis.
  • LARAVEL-9 (7) Keep browser routes in the web middleware group, where the PreventRequestForgery middleware checks them, add @csrf to every POST, PUT, PATCH and DELETE form, and exclude only routes that can't send a token, such as third-party webhooks, from CSRF protection. (specific/laravel) Automatable: Semgrep Laravel rules.
  • LARAVEL-11 (7) Eager load the relationships that each query's results use with with() or load(), and call Model::preventLazyLoading(! $this->app->isProduction()) in AppServiceProvider, so that lazy loading throws an exception in development and tests. (specific/laravel)
  • LARAVEL-12 (7) Wrap writes that must succeed or fail together in DB::transaction(), pass attempts to retry on deadlocks, and dispatch queued jobs from inside a transaction only after it commits, with the queue connection's after_commit option or ->afterCommit(). (specific/laravel) Automatable: Larastan rules.
  • LARAVEL-13 (7) Run slow work, such as processing uploaded files, in queued jobs; make each job safe to run more than once, keep each worker's --timeout several seconds shorter than the connection's retry_after, limit the attempts, and keep failed jobs in the failed_jobs table to inspect and retry them. (specific/laravel)
  • LARAVEL-14 (6) Write most tests as feature tests that send HTTP requests to the application and assert on the response and the database, reset the database for each test with RefreshDatabase, and create test data with model factories. (specific/laravel)
  • LARAVEL-15 (6) Check the code style with Laravel Pint, and analyse the code with Larastan, the PHPStan extension for Laravel, in CI. (specific/laravel) Automatable: Larastan rules, Laravel Pint --test.