PhpStorm 如何消除 API Resources 中 $this->id 时的 Property accessed via magic method 警告
使用 PhpStorm 编辑 API Resource 类代码时,遇到一个小问题,使用 $this->id
的时候,会报警 Property accessed via magic method,虽然不影响代码运行,我还是希望消除,大家有遇到吗?除了不管或者直接关闭该项检查,有啥更加理想的办法吗?
class UploadResource extends JsonResource
{
public function toArray(Request $request): array
{
// return parent::toArray($request);
return [
'id' => $this->id,
'path' => $this->path,
'file_name' => $this->file_name,
'alt' => $this->alt,
'mime_type' => $this->mime_type,
'size' => $this->size,
'disk' => $this->disk,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}
我使用了 Laravel Idea 插件,但是也不能消除该警告。
我又调查了下,正解是 mixin DocBlock,如下:
我通过 GitHub 搜索发现这个的,然后 Google 又找到了这篇靠谱的博文: freek.dev/1482-the-mixin-php-docbl...