How to get data from SQL in laravel using whereIn and take function?

Gaurav :

How can I get data of each value in the array. I want only 1 result from both values.

$userBikes = array('862549040389788','12345');


$data = DB::table('geolocation')
->whereIn('Imei',$userBikes)
->take(1)      
->get();

Result:

["28.537857", "77.269325", "862549040389788"]

but I am expecting this result:

["28.537857", "77.269325", "862549040389788"]
["28.537857", "77.269325", "12345"]
IGP :

Based on your comments, I think you want a group by query.

$userBikes = array('862549040389788','12345');

$data = DB::table('geolocation')
->whereIn('Imei', $userBikes)
->groupBy('Imei')
->selectRaw('any_value(id) as id, any_value(Lat) as Lat, any_value(Lng) as Lng, any_value(created_at) as created_at, Imei')
->get();

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=401719&siteId=1