phplaravelphpstormphpdoc

How to navigate Laravel model scopes in PhpStorm


I have a model CheckingAccount with scopes:

//scopes
public function scopeEmailLike(Builder $builder, $email)
{
    return $this->where($this->table . '.email', 'like', '%' . $email . '%');
}

public function scopePhoneLike(Builder $builder, $phone)
{
    return $this->where($this->table . '.phone', 'like', '%' . $phone . '%');
}

But PhpStorm fails to recognize them in other classes. For example here in controller:

public function all($filters)
{
    return CheckingAccount::query()
        ->emailLike($filters['email'])
        ->phoneLike($filters['phone'])
        ->get();
}

It says method emailLike() not found and phoneLike() is not even recognized at all. What is wrong?


Solution

  • Äs LazyOne said

    1. There is no real method emailLike() -- it is magic one (during runtime Laravel uses scopeEmailLike() instead). Try declaring such method using @method in a PHPDoc for the class.
    2. Consider using Laravel Idea plugin -- it's a paid one BUT it offers A LOT of features for Laravel development, especially for code completion. And it's in active development. At very least give it a try.