Skip to content

Rules

Rules for mistakes that Laravel will happily let you make at runtime, grouped below by what they cover and listed by default at the end.

Each rule is documented with its error identifier, the option that switches it on or off, and its default. Toggles live under laravel.rules and are named after what the rule reports, so rules.modelMake is the switch for laravel.modelMake:

parameters:
    laravel:
        rules:
            modelMake: false
            unusedView: true

On by default

Rule Identifier
Model make laravel.modelMake
Model appends laravel.modelAppends
Unnecessary collection call laravel.unnecessaryCollectionCall
Unnecessary enumerable toArray call laravel.unnecessaryEnumerableToArrayCall
Config accessor laravel.configAccessor
Env call outside config laravel.envCallOutsideConfig

Always enabled

These report unconditionally. There is no option to switch them off, because each one reports something that is a bug in every codebase rather than a matter of taste. Ignore by identifier if you need an exception.

Rule Identifier
Relation existence laravel.relationExistence
Dispatch argument types laravel.jobs.noConstructor, laravel.events.noConstructor
Undefined console argument or option laravel.console.undefinedArgument, laravel.console.undefinedOption
Deferrable service provider without provides() laravel.deferrableServiceProvider.missingProvides
Useless value() call laravel.uselessConstructs.value
Useless with() call laravel.uselessConstructs.with

Off by default

Off for one of two reasons: the rule enforces a style choice rather than finding a bug, or it depends on a scan that can be incomplete, in which case the gap shows up as a false positive rather than as silence.

Rule Identifier Off because
Model method visibility laravel.modelMethodVisibility.scope, ….accessor style
Model forwarding to builder laravel.modelForwardingToBuilder style
Model static forwarding to builder laravel.modelStaticForwardingToBuilder style
Octane compatibility laravel.octaneCompatibility only applies under Octane
Auth in request scope laravel.authInRequestScope.facade, ….helper style
Unused view laravel.unusedView scan can be incomplete
Missing translation laravel.missingTranslation scan can be incomplete

Not a rule

Checking column names looks like a rule and is often described as one, but it is a type. Enabling modelPropertyType activates model-property<Model>, after which PHPStan's ordinary argument checks do the reporting, so the errors carry core identifiers such as argument.type rather than a laravel. one.

It is worth turning on anyway. It is the single highest-value option here.

Ignoring

Prefer ignoring by identifier over ignoring by message or by line. Identifiers are covered by the backward compatibility policy and message wording is not, so a message-based ignore can stop matching in any release.

parameters:
    ignoreErrors:
        - identifier: laravel.modelMake

Every identifier is listed here.