id | 代理_id | 货币 |
---|---|---|
1 | A0001 | 印尼盾 |
2 | A0002 | 马币 |
3 | A0001 | 泰铢 |
示例当前具有如上的数据集。有没有办法仅使用 1 个查询生成器来获得如下结果?
Output:
[
"agent_id" => "A0001",
"currency" => [
"IDR",
"THB",
],
],
[
"agent_id" => "A0002"
"currency" => ["MYR"]
]
基本上就像试图在同一个代理下采摘货币。
找到了解决这个问题的方法
$output = $output
->get()
->groupby('agent_id')
->map(function($rows){
return [
"agent_id" => $rows[0]['agent_id'],
"currency" => $rows->pluck('currency'),
];
});