How can I convert the code below to a single query in eloquent ?
The table has the following columns ( id (primary index) - sku - serial_number - status - created_at - updated_at)
The aim is to retrieve the latest status 'latest record' of each product that shares the same SKU.
// get all the products that shares the same sku number
$list_of_products_status = Product_status::where('sku', 'sku-number')
->get();
$list_unique_serials = $list_of_products_status->pluck('serial_number')->toArray();
$products= collect([]);
foreach ($list_unique_serials as $serial)
{
// get the latest status of each product
$product = Product_status::where('serial_number', $serial)
->latest()->first();
$products[] = $product;
}