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.
Strongly recommended (9–10)¶
-
LARAVEL-1(9) Never commit the.envfile: commit.env.examplewith 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, setAPP_DEBUGtofalseand point the web server's document root at thepublicdirectory. (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'sauthorize()method, or with thecanmiddleware. (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 withJs::from(). (specific/laravel) Automatable: Psalm Laravel plugin, security analysis. -
LARAVEL-6(9) Pass values to raw SQL only as bindings, with?or named placeholders, inDB::select(),whereRaw(),orderByRaw()and the other raw methods, and never let user input choose column names, includingorderBycolumns. (specific/laravel) Automatable: Psalm Laravel plugin, security analysis.
Recommended (6–8)¶
-
LARAVEL-7(8) Validate every request with a Form Request or the validator, pass only the validated data ($request->validated()orsafe()) tocreate(),fill()andupdate(), and declare each model's mass-assignable attributes with theFillableattribute (the$fillableproperty before Laravel 13) instead of unguarding the model. (specific/laravel) Automatable: Semgrep Laravel rules. -
LARAVEL-10(8) Change the schema only through migrations indatabase/migrations, run them in each deployment withphp artisan migrate --force, and add--isolatedwhen 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) Runphp artisan optimizein every deployment, to cache the configuration, events, routes and views; callenv()only in the files inconfig/; and restart queue workers and other long-running processes after deploying, for example withphp artisan reload. (specific/laravel) Automatable: Larastan rules. -
LARAVEL-8(7) Validate the type and size of every upload with theFilerule, for exampleFile::types([...])->max('10mb')orFile::image(), and store it under a generated name withstore()orhashName(), never a name built fromgetClientOriginalName(),getClientOriginalExtension()or other user input. (specific/laravel) Automatable: Psalm Laravel plugin, security analysis. -
LARAVEL-9(7) Keep browser routes in thewebmiddleware group, where thePreventRequestForgerymiddleware checks them, add@csrfto everyPOST,PUT,PATCHandDELETEform, 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 withwith()orload(), and callModel::preventLazyLoading(! $this->app->isProduction())inAppServiceProvider, so that lazy loading throws an exception in development and tests. (specific/laravel) -
LARAVEL-12(7) Wrap writes that must succeed or fail together inDB::transaction(), passattemptsto retry on deadlocks, and dispatch queued jobs from inside a transaction only after it commits, with the queue connection'safter_commitoption 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--timeoutseveral seconds shorter than the connection'sretry_after, limit the attempts, and keep failed jobs in thefailed_jobstable 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 withRefreshDatabase, 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.