I want to get last three prices (6,7,8). I don't need Limit.
id: 8
is an update from id: 5
,
id: 8
should show instead of id: 5
[
{
id: 5,
product_id: 1,
seller_id: 26,
color_id: 18,
warranty_id: 29,
price: 1000000,
created_at: "2017-05-27 09:33:44",
},
{
id: 6,
product_id: 1,
seller_id: 26,
color_id: 19,
warranty_id: 30,
price: 1200000,
created_at: "2017-05-27 09:33:56",
},
{
id: 7,
product_id: 1,
seller_id: 26,
color_id: 21,
warranty_id: 33,
price: 900000,
created_at: "2017-05-27 09:34:06",
},
{
id: 8,
product_id: 1,
seller_id: 26,
color_id: 18,
warranty_id: 29,
price: 600000,
created_at: "2017-05-27 10:21:23",
}
]
My try:
$product->get_prices()
->groupby(['product_id','color_id','warranty_id','seller_id'])
->latest()
->get();
// 5,6,7,8
Product.php
function get_prices(){
return $this->hasMany('\App\Price');
}