[Bug]: Model scopes shown as unused
Bug description
Environment
- PhpStorm version: 2025.1.2 (Build #PS-251.26094.133, built on June 5, 2025)
- Laravel Idea plugin version: 10.2.2.251
- Laravel version: v12.18.0
- PHP version: 8.4
Description
Model scopes are not recognized as “used” by Laravel Idea when they are called through the query builder. Example:
use App\Models\HardwareMaintenanceLog;
HardwareMaintenanceLog::byStatus('completed')->get();
The scope byStatus is correctly defined inside the HardwareMaintenanceLog model, but Laravel Idea does not:
- mark the scope as “used” in the gutter/code lens;
- offer “Go to declaration” or show a reference count;
- include the scope in “Find usages” results.
Expected behaviour
- The scope should be detected as used when called via
Model::scopeName()or its camel-cased alias (Model::name()). - IDE gutter/lens should show reference counters.
- “Go to declaration” (⌘/Ctrl + B) should jump to the scope definition.
Actual behaviour
- No reference counter is shown.
- Scope appears as unused in IDE inspections.
Additional info
- Tried Invalidate Caches / Restart – no change.
- Scopes are located in the same namespace/file as the model.
- Autocomplete for the scope works; only reference tracking is missing.
Plugin version
10.2.2.251
Operating system
Linux
Steps to reproduce
-
Create a Laravel model:
class HardwareMaintenanceLog extends Model { public function scopeByStatus($query, string $status): void { $query->where('status', $status); } } -
Call the scope somewhere in the code:
HardwareMaintenanceLog::byStatus('completed')->get(); -
Observe that Laravel Idea does not detect any usages of
scopeByStatus.
Relevant log output
Thanks for your report! I've added this to internal task tracker.
Can you please check, if toggling this option in plugin will help?
It may not fix code lens counter, but we will work on that as well.
I have the same situation. I have tried enabling the "Implicit eloquent method usages" check box and it did not help.
/**
* scope to fetch only published products
*
* @param Builder<self> $query
* @return Builder<self>
*/
protected function scopePublished(Builder $query): Builder
{
return $query->where('status', ProductStatusType::PUBLISHED->value);
}
/**
* @param Builder<self> $query
* @return Builder<self>
*/
protected function scopeAdEligibleProducts(Builder $query): Builder
{
return $query->published()
->whereActive(true)
->whereHas('featuredImage')
->where('quantity', '>', 0);
}
@ElvisIsKing666 I've checked your case. Everything works in the 11.0.1 version. It shows scopePublished as "used" and "scopeAdEligibleProducts" as "notUsed"
But if I use this scope anywhere, it immediately becomes normal, "used".
@gorbunov The "Implicit Eloquent method usages searcher" option changes behaviour to be as expected, but I am hesitant to leave it on because of the CPU usage warning.
It would be awesome if you could optimise the algorithm somehow!
I am hesitant to leave it on because of the CPU usage warning.
It's just that phpStorm's ImplicitUsageSearcher internal interface is marked as resource intensive, since usages will be actively updated on document edit instead of using reference cache, and it needed for usage search of things that linked by "magic strings" (strings with class names, configs strings, etc.). Search itself is optimized, but we decided still keep warning for user discretion.
In reality, unless you on old laptop, or low on battery power (in power saving mode this feature may be disabled by IDE itself), or working on giant monorepo you will likely won't notice any higher CPU usage