[英]Nested Mapped Laravel Query with Relationships
I am outputting a query which has a relationship with another model.我正在输出一个与另一个模型有关系的查询。
One of the fields I need is within the relationship我需要的字段之一是在关系内
$officeFlagMap = $officeFlagQuery->map(function ($item) {
return [
'propagent_id' => $propagent_id,
];
$item->theAgent->map(function ($inner){
return [
'agtFullName' => $inner->agtFullName,
];
});
});
I have checked that both values are correct but I am only getting the output for the $inner->agtFullName.
我已经检查过两个值是否正确,但我只得到
$inner->agtFullName.
的输出$inner->agtFullName.
How can I modify this to chain the returns and show both fields?如何修改它以链接返回并显示两个字段?
an ideal code would be,一个理想的代码是,
$officeFlagMap = $officeFlagQuery->map(function ($item) {
return [
'propagent_id' => $item->propagent_id, // use the appropriate variable here
'agtFullName' => $item->theAgent->map(function ($inner){
return [
'agtFullName' => $inner->agtFullName,
];
});
];
});
this will map over the original collection and again on the theAgent
collection and will return the result.这将映射原始集合并再次映射到
theAgent
集合,并将返回结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.