Search code examples
phplaravellaravel-5idephpstorm

PhpStorm not recognizing methods


So this has been asked several times but I'm yet to find an answer that works.

I'm using PhpStorm - 2016.3.2 and Laravel 5.4

enter image description here

I have tried using https://github.com/barryvdh/laravel-ide-helper and also the Laravel plugin for PhpStorm.

I tried checking the option "Downgrade severity if_magic methods are present in class" - this didn't work.

The only thing I can do to solve this is to turn the warnings off completely for undefined methods, but turning features like this off defeat the point of using an IDE.

Has anyone found a way to solve this?

Sources:

https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/15

https://laracasts.com/discuss/channels/general-discussion/why-does-phpstorm-not-recognise-all-the-classes?page=1

PhpStorm laravel 5 method not found

https://github.com/barryvdh/laravel-ide-helper


Solution

  • The reason this is happening is because PHPStorm doesn't know what that variable is meant to be (it has nothing to be with Laravel). As far as PHPStorm knows it's just a param for a method.

    As @LazyOne suggested, you can type hint the variable e.g.

    public function scopeIncomplete(Builder $query)
    

    Then at the top of the class just add the following use statement

    use Illuminate\Database\Eloquent\Builder;
    

    Alternatively, if you're using a OS X (I'm not sure of the shortcuts for Windows or Linux) you can move the caret in the Builder reference and then hit alt enter to import the class.

    Hope this helps!