orderBy() can be simplified
Reports orderBy($column, $direction) calls that can be rewritten with a shorter, equivalent helper. The call may be on a query/Eloquent builder or directly on a model (e.g. User::orderBy(...)).
The suggested helper depends on the column name. For date-like columns (those ending with _at or containing date/time) the more expressive latest()/oldest() helpers are offered; for other columns orderByDesc() is offered for the descending direction. Ascending order on a non-date column is left untouched.
Examples:
$query->orderBy('read_at', 'desc'); // -> $query->latest('read_at'); $query->orderBy('created_at', 'asc'); // -> $query->oldest(); $query->orderBy('priority', 'desc'); // -> $query->orderByDesc('priority'); User::orderBy('created_at', 'desc'); // -> User::latest();
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
LaravelSimplifyOrderBy- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
Inspection ID: LaravelSimplifyOrderBy
Suppressing Inspection
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |