Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

lint/laravel

Laravel (ecosystem: on when composer.lock has laravel/framework). Also in format (1) and analyse (15).

add-factory-extends-phpdoc

Adds the @extends annotation to Factories.

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed. Gated by laravel-version.

add-has-factory-trait

Adds the HasFactory trait to Models.

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

add-legacy-relation-generics

Add generic return type to relations in child of Illuminate\Database\Eloquent\Model

In the types set. Unsafe fix: it can change behaviour. Runs when laravel is installed. Planned: not in Pun yet. Enabling it is a config error.

add-new-relation-generics

Add generic return type to relations in child of Illuminate\Database\Eloquent\Model

In the types set. Unsafe fix: it can change behaviour. Runs when laravel is installed. Planned: not in Pun yet. Enabling it is a config error.

add-query-closure-type

Type-hint the closure parameter of Eloquent where()/whereHas() and similar query methods.

In the types set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

add-relation-generics

Add generic return type to relations in child of Illuminate\Database\Eloquent\Model

In the types set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

add-relation-query-closure-type

Add type hinting to where relation has methods e.g. whereHas, orWhereHas, whereDoesntHave, orWhereDoesntHave, whereHasMorph, orWhereHasMorph, whereDoesntHaveMorph, orWhereDoesntHaveMorph

In the types set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

add-scope-builder-generics

Add generic Builder return type to scopes in child of Illuminate\Database\Eloquent\Model

In the types set. Unsafe fix: it can change behaviour. Runs when laravel is installed. Planned: not in Pun yet. Enabling it is a config error.

add-tap-closure-type

Automatically type hints your tappable closures

In the types set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

no-app-array-access

Replace magical call on $this->app[“something”] to standalone type assign variable

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

no-collection-aliases

Use the base collection methods instead of their aliases.

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

no-controller-middleware

This rule warns against applying middlewares in controllers.

Not in any set. Report only. Runs when laravel is installed.

no-default-authorize

Remove the authorize() method from FormRequest classes when it only returns true, as passesAuthorization() defaults to true when the method does not exist

In the code-quality set. Safe fix. Runs when laravel is installed. Planned: not in Pun yet. Enabling it is a config error.

no-implicit-model-query

Start Eloquent queries with Model::query() instead of static magic calls.

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

no-negated-blank-filled

Swap the use of NotBooleans used with filled() and blank() to the correct helper.

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

no-negated-contains

Convert negated calls to contains to doesntContain, or vice versa.

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

no-negated-filter

Avoid negated conditionals in filter() by using reject(), or vice versa.

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

no-negated-when

Reverse conditionable method calls

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

no-request-all

Detects the use of $request->all() or Request::all() in Laravel applications.

In the code-quality set. Report only. Runs when laravel is installed.

no-useless-value-call

Removes redundant value helper calls

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

no-useless-with-call

Removes redundant with helper calls

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-abort-if

Change if abort to abort_if

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-aliases-attribute

Changes the aliases property to use the Aliases attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-anonymous-migration

Prefer using anonymous classes for Laravel migrations instead of named classes.

In the code-quality set. Report only. Runs when laravel is installed.

prefer-appends-attribute

Changes model appends property to use the appends attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-array-validation-rules

Use array syntax for validation rules instead of ‘a|b’ strings.

In the code-quality set. Safe fix. Runs when laravel is installed.

prefer-back-helper

Replace redirect()->back() and Redirect::back() with back()

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-backoff-attribute

Changes the backoff property to use the Backoff attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-casts-method

Detects the $casts property on an Eloquent model. Laravel 11 introduced the casts()

In the coding-style set. Safe fix. Runs when laravel is installed.

prefer-class-container-key

Changes the string or class const used for a service container make call

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-closure-only-bind

Drop the specified abstract class from the bind method and replace it with a closure that returns the abstract class.

Not in any set. Safe fix. Runs when laravel is installed.

prefer-collected-by-attribute

Changes model newCollection method to use the CollectedBy attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-collection-all

Convert toArray() to all() when the collection does not contain any Arrayable objects.

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-collection-is-empty

Convert collection count() comparisons against 0 or 1 to isEmpty() or isNotEmpty()

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed. Planned: not in Pun yet. Enabling it is a config error.

prefer-collects-attribute

Changes the collects property to use the Collects attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-command-hidden-attribute

Changes the hidden property to use the Hidden attribute on console commands

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-connection-attribute

Changes model connection property to use the Connection attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-constructor-injection

Move help facade-like function calls to constructor injection

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-container-method-call

Change array access on the container to the matching method call, as the contract does not extend ArrayAccess

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed. Planned: not in Pun yet. Enabling it is a config error.

prefer-date-facade

Refactor Carbon static method calls to use the Date facade instead.

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-date-format-attribute

Changes model dateFormat property to use the DateFormat attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-dedicated-status-assertion

Use assertOk(), assertNotFound() and similar instead of assertStatus(200).

In the code-quality set. Safe fix. Runs when laravel is installed.

prefer-default-argument

Apply default instead of null coalesce

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-delay-attribute

Changes the delay property to use the Delay attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-delete-when-missing-models-attribute

Changes the deleteWhenMissingModels property to use the DeleteWhenMissingModels attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-description-attribute

Changes the description property to use the Description attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-dispatch-helper

Use the event or dispatch helpers instead of the static dispatch method.

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-env-helper

Change env variable to env static call

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-environment-check

Replace app environment comparison with parameter or method call

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-error-bag-attribute

Changes the errorBag property to use the ErrorBag attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-exception-class-string

changes use of a new throw instance to class string

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-explicit-json-call

Change method calls from $this->json to $this->postJson, $this->putJson, etc.

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-facade-over-app

Change app() func calls to facade calls

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-fail-on-timeout-attribute

Changes the failOnTimeout property to use the FailOnTimeout attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-fake-helper

Use the fake() helper instead of $this->faker.

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-file-facade-delete

Use the File facade instead of the unlink() function.

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed. Planned: not in Pun yet. Enabling it is a config error.

prefer-fillable-attribute

Changes model fillable property to use the fillable attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-guarded-attribute

Changes model guarded property to use the guarded attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-help-attribute

Changes the help property to use the Help attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-hidden-attribute

Changes model hidden property to use the hidden attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-job-connection-attribute

Changes the connection property to use the Connection attribute on queue jobs

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-latest-oldest

Changes orderBy() to latest() or oldest()

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-max-exceptions-attribute

Changes the maxExceptions property to use the MaxExceptions attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-nullsafe

Convert simple calls to optional helper to use the nullsafe operator

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-pivot-class

Changes the pivot table name of a many to many relation to the pivot model class.

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed. Planned: not in Pun yet. Enabling it is a config error.

prefer-preserve-keys-attribute

Changes the preserveKeys property to use the PreserveKeys attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-protected-model-methods

Makes Model attributes and scopes protected

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed. Upstream gates: checkModelMethodVisibility (default false).

prefer-queue-attribute

Changes the queue property to use the Queue attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-report-if

Change if report to report_if

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-repository-method-call

Change array access on a config or cache repository to the matching method call, as the contracts do not extend ArrayAccess

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed. Planned: not in Pun yet. Enabling it is a config error.

prefer-request-facade

Use the Request facade instead of $_GET, $_POST and $_SERVER.

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-request-server

Change server variable to Request facade’s server method

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-request-validate

Change Request::validate() and request() to an injected $request. Adds a Request $request parameter to the method, so update its callers.

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-resolve-helper

Convert app() to resolve() where applicable.

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-route-key-attribute

Changes model getRouteKeyName() method to use the RouteKey attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed. Planned: not in Pun yet. Enabling it is a config error.

prefer-session-facade

Change PHP session usage to Session Facade methods

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-signature-attribute

Changes the signature property to use the Signature attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-sleep-facade

Use Sleep::sleep() and Sleep::usleep() instead of the sleep() and usleep() function.

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-stop-on-first-failure-attribute

Changes the stopOnFirstFailure property to use the StopOnFirstFailure attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-str-starts-with

Use Str::startsWith() or Str::endsWith() instead of substr() === $str

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-table-attribute

Changes model table-related properties to use the Table attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-throw-if

Change if throw to throw_if

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-timeout-attribute

Changes the timeout property to use the Timeout attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-to-route-helper

Replace redirect()->route("home") and Redirect::route("home") with to_route("home")

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-today

Use today() instead of now()->startOfDay()

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-touches-attribute

Changes model touches property to use the touches attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-travel-to

Use the $this->travelTo() method in Laravel’s TestCase class instead of the Carbon::setTestNow() method.

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-tries-attribute

Changes the tries property to use the Tries attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-typed-assert-closure

Changes assert calls to use a type hinted closure.

In the code-quality set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-unguarded-attribute

Changes model empty guarded property to use the Unguarded attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed. Planned: not in Pun yet. Enabling it is a config error.

prefer-unique-for-attribute

Changes the uniqueFor property to use the UniqueFor attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-view-array

Prefer passing data to views using the array parameter in the view() function,

Not in any set. Report only. Runs when laravel is installed.

prefer-visible-attribute

Changes model visible property to use the Visible attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-without-incrementing-attribute

Changes model incrementing = false property to use the WithoutIncrementing attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

prefer-without-timestamps-attribute

Changes model timestamps = false property to use the WithoutTimestamps attribute

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

require-final-controller

Enforces that controller classes are declared as final.

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

require-phpdoc-types-only

Keeps only type annotations in PHPDoc.

Not in any set. Unsafe fix: it can change behaviour. Runs when laravel is installed.

Last updated on

Was this page helpful?