Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 679
владимир зайцев Avatar asked Oct 24 '25 04:10

владимир зайцев


1 Answers

Ä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.
like image 132
владимир зайцев Avatar answered Oct 26 '25 19:10

владимир зайцев



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!