如何在 PhpStorm 中导航 Laravel 模型范围

вла*_*цев 3 php phpdoc phpstorm laravel

我有一个CheckingAccount带有范围的模型:

//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 . '%');
}
Run Code Online (Sandbox Code Playgroud)

但 PhpStorm 无法在其他类中识别它们。例如在控制器中:

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

emailLike()它说找不到方法,甚至phoneLike()根本不被识别。怎么了?

вла*_*цев 5

\xc3\x84s LazyOne 说

\n
    \n
  1. 没有真正的方法emailLike()——它是神奇的方法(在运行时 Laravel 使用scopeEmailLike())。@method尝试在类的 PHPDoc 中使用声明此类方法。
  2. \n
  3. 考虑使用 Laravel Idea 插件——它是一个付费插件,但它为 Laravel 开发提供了很多功能,尤其是代码完成功能。而且它正在积极开发中。至少尝试一下。
  4. \n
\n