Ad

How To Get Data From SQL In Laravel Using WhereIn And Take Function?

- 1 answer

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"]
Ad

Answer

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();
Ad
source: stackoverflow.com
Ad