Eloquent ORM Code Hinting in PhpStorm

后端 未结 6 1583
再見小時候
再見小時候 2020-12-08 00:57

So I\'m just starting off with Laravel (using v5) and Eloquent. I\'m working on getting some basic APIs up and running and noticing that a lot of working methods don\'t show

6条回答
  •  忘掉有多难
    2020-12-08 01:29

    A little late but I recently had the same problem so I thought I would put a note down:

    This is because Database\Eloquent\Model.php has a query() function which returns \Illuminate\Database\Eloquent\Builder and the Eloquent\Builder has a line:

    use Illuminate\Database\Query\Builder as QueryBuilder;
    

    Then it uses 'magic' __call methods to call to functions in Query\Builder. (look for __call method in Eloquent\Builder)

    See: http://php.net/manual/en/language.oop5.overloading.php#object.call

    __call() is triggered when invoking inaccessible methods in an object context.

    So, indeed the method you are calling is inaccessible :) There is not much that the IDE can do.

    There are workarounds like using @method tags but it is unmaintainable. An alternative is to use @mixin (but this is not standards based). See: https://github.com/laravel/framework/issues/7558

    I think this all be resolved when they get rid of all the magic calls in the Laravel code and use PHP 'traits' instead. See last message here. :)

提交回复
热议问题