Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 773
Brad Avatar asked Jun 10 '26 20:06

Brad


2 Answers

PHPDoc blocks can come in handy for this.

You can add this PHP comment just before the statement return $query, inside the function

/** @var $query \Illuminate\Database\Query\Builder */

In this way PHPStorm will correctly recognize the method

like image 136
Leonardo Atalla Avatar answered Jun 13 '26 10:06

Leonardo Atalla


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!

like image 28
Rwd Avatar answered Jun 13 '26 10:06

Rwd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!