Laravel-ide-helper: Errors in Laravel 5.6

Created on 3 Mar 2018  路  7Comments  路  Source: barryvdh/laravel-ide-helper

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.

Most helpful comment

@BinotaLIU thanks

All 7 comments

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.

https://github.com/laravel/framework/blob/b3413ad53c50de85ef4d83425230eae2746ff828/src/Illuminate/Database/Eloquent/Model.php#L1557-L1583

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 :}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Alymosul picture Alymosul  路  4Comments

Gummibeer picture Gummibeer  路  3Comments

beniaminorossini picture beniaminorossini  路  5Comments

4n70w4 picture 4n70w4  路  3Comments

Lambik picture Lambik  路  5Comments