0
id agent_id currency
1 A0001 IDR
2 A0002 MYR
3 A0001 THB

example currently have a dataset as above, is it have any way to using only 1 query builder to get the outcome like below

Output:

[
        "agent_id" => "A0001",
        "currency" => [
            "IDR",
            "THB",
    ],
],
[
        "agent_id" => "A0002"
        "currency" => ["MYR"]
]

Basically likes try to pluck the currency under same agent
Appreciate for all the suggestion.

Wei Kang
  • 163
  • 2
  • 9

1 Answers1

0

Found a solution for this problem

   $output = $output
    ->get()
    ->groupby('agent_id')
    ->map(function($rows){
      return [
        "agent_id" => $rows[0]['agent_id'],
        "currency" => $rows->pluck('currency'),
      ];
   });
Wei Kang
  • 163
  • 2
  • 9