I use the latest version of laravel with PHPStorm. i did everything but still ide helper doesnt work as it should.. i still get errors like :
Return value is expected to be '\Illuminate\Http\Response', '\Illuminate\Http\Resources\Json\AnonymousResourceCollection' returned less... (Ctrl+F1)
Return value type is not compatible with declared.
and
Non-static method 'where' should not be called statically less... (Ctrl+F1)
Dynamic class method called as static.
auto completion works though.
This error is produced from the PHPDocs that are generated automatically by laravel. I return a collection and it doesnt recognise it.
i get the same problem, PHPStorm can't recognize where method of Model
laravel/framework: v5.6.19
I don't understand where the first error show up, can you provide your code?
For the second warning:
The where() method is not defined as a static method.
To avoid this warning, you can simply call the Model::query() first:
<?php
User
::query()
->where('is_vip', true)
->count();
@BinotaLIU thanks
@BinotaLIU that query:: trick is a big help. Does it take away any benefit of eloquent?
@GigaMick No. You can check the source code, when you try to build a query with an Eloquent model, it will call Model::query() internally to new an Illuminate\Eloquent\Builder instance.
Eloquent\Model has never implement where/find... etc., all query method is handled by Model::__callStatic and Model::__call.
some might ask if Eloquent\Model didn't implement where, why it will rise an Non-static method 'where' should not be called statically warning?
this is because ide-helper will add @mixin \Illuminate\Database\Eloquent\Builder and @mixin \Illuminate\Database\Query\Builder on it's phpdoc block.
@barryvdh you can close this unless you have another solution
@barryvdh this works nowadays correctly, issue can be closed :}
Most helpful comment
@BinotaLIU thanks