【发布时间】:2023-04-02 10:57:01
【问题描述】:
我有这个问题:
FHINotification::with(['log'])
->where('user', $user->getSAMAccountName())
->whereNull('read_at')
->get();
“Log”模型具有获取自定义数据的功能(比数据库中的数据更具可读性)
public function getData(): array
{
Game::setWithoutStandardEdition(true);
$ldapService = App::make('App\Services\LdapService');
$log['url'] = $this->getUrl($this->task->resourceable_type, $this->task->string_resourceable_id);
$log['action'] = $this->getActionName($this->action);
$log['resource_name'] = $this->getResourceName($this->task->resourceable);
$log['user'] = $ldapService->getUserByUsername($this->user)->getDisplayName();
return $log;
}
我可以从 Log 实例调用此方法,例如:$log->getData() 但是否可以从查询生成器调用它?
如果没有,我必须循环我的查询结果来格式化它们中的每一个。
谢谢你:)
【问题讨论】:
标签: laravel eloquent relationship builder eager-loading