我有一个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()根本不被识别。怎么了?
我有一个带有方法的控制器
public function foo(FooRequest $request)
{
return "OK"
}
Run Code Online (Sandbox Code Playgroud)
FooRequest 扩展了 FormRequest 并具有
public function rules()
{
return [
'id' => ['required', 'numeric', 'exists:partners,id'],
'manager_id' => ['nullable', 'numeric'],
];
}
Run Code Online (Sandbox Code Playgroud)
如果我输入无效 ID,它会将我重定向到 /。如何禁用此重定向并显示 json 异常?
json 异常已经实现(类似于 JException(code, 异常, 错误),我只需要了解如何摆脱重定向并调用此 JException