I have following structure, just attaching screenshot for reference, consider the attached image is my sql schema
This is what I am trying to get
$array = [
    [
        'city'  =>  1,
        'google'=>  [4,2]
    ],
    [
        'city'  =>  2,
        'google'=>  [3,2,1]
    ],
];
I have used Postgresql
I tried with group by though no logic behind my implementation, no magic involved in laravel
$models = Model::groupBy('city')->get();
Can anyone help to find the way?
Thought of doing it through loop but would like to know the efficient way of doing it.

 
     
     
    
