Resource 使用错误
qdsay opened this issue · 4 comments
qdsay commented
例:/Console/stubs/Resources/Menu.php
在菜单列表中,资源Resource 会随数据个数的多少实例化N次,父类:resource中的toArray()方法也会反复调用N次,toArray()方法请求$this->getFields($request)方法时造成fields()方法中的:foreach Permission::all() 和 \QuarkCMS\QuarkAdmin\Models\Menu::orderedList()方法也会调用N次...
tangtanglove commented
我排查一下
tangtanglove commented
你说的情况确实存在,这是因为所有获取Fields的方法都会调用相关Resource里面的fields(Request $request)方法。
tangtanglove commented
如果有啥好的建议和优化方案,可以提给我
qdsay commented
/Console/stubs/Resources/Menu.php
/**
* 将资源转换成数组
*
* @param Request $request
* @return array
*/
public function toArray($request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'guard_name' => $this->guard_name,
'icon' => $this->icon,
'type' => $this->type,
'path' => $this->path,
'pid' => $this->pid,
'sort' => $this->sort,
'status' => $this->status,
];
}