Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mjsarfatti's avatar

PhpStorm, Laravel and CodeSniffer: query scope method not found?

I'm using local query scopes ( https://laravel.com/docs/6.x/eloquent#local-scopes ) in a functioning app. Recently added CodeSniffer to PhpStorm, and I get all these problems since the scope is defined in the model as "scopeNameOfTheScope", but it's used in the controller as "nameOfTheScope".

See an example of the problem here: https://imgur.com/OMQqwp8

By the way, I have installed the Laravel plugin, and generated my ide_helper ( https://github.com/barryvdh/laravel-ide-helper )

Am I missing something? Is there any way I can tell CS to recognize scopes?

EDIT

Actually I realized it's not CodeSniffer, it's the Inspection. But my question remains, how do I tell PhpStorm that it's fine, it's just a local scope?

0 likes
4 replies
mjsarfatti's avatar

Yes, I've run:

php artisan ide-helper:generate
php artisan ide-helper:models
php artisan ide-helper:meta

But actually I've restarted the computer and the problem seems gone now 🤷‍♂️

The only remaining minor annoyance is that in my model file Inspection still complains about "Unused element: 'scopeNameOfTheScope'". I can live with it I guess...

dmitry.g.ivanov's avatar
The only remaining minor annoyance is that in my model file Inspection still complains about "Unused element: 'scopeNameOfTheScope'". I can live with it I guess...

@mjsarfatti There's a workaround that I've found in the recent PHPStorm versions:

In the PHPStorm, go to:

Settings > Editor > Inspections > PHP > Unused > Unused declaration > Entry points > CODE PATTERNS;

And add this pattern:

  • Class: \App\* (or \App\Models\*);
  • Member: scope*;

After that, all scope* methods in the specified namespace would be ignored by that inspection.

I hope it helps!

11 likes

Please or to participate in this conversation.