Level 73
Since you are just looping over it, then you should use map, but there is nothing really wrong with a classic foreach.
It does look just like you are converting an eloquent collection to an array.
If so just use the toArray method.
return $data->toArray();
If that is not the case you could make it a little cleaner.
function whatever($data)
{
$result = [];
foreach ($data as $datum) {
$result[] = [
'product_id' => $datum->product_id,
'total' => $datum->total,
'date' => $datum->date,
'total_surface' => $datum->total_surface,
'batch' => $datum->batch,
];
}
return $result;
}
1 like