Level 2
try this for the first query:
OrderStatusDetail::whereIn('id', function($query){
$query->max('id')
-> groupBy('order_detail_id');
})->where('order_id',210)->get()->toArray();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
SELECT * FROM `order_status_details` WHERE id IN(select max(id) from order_status_details group by `order_detail_id`) and order_id=210
i Want to add above query into this
OrderStatusDetail::with(['orderStatus'=>function($query){
$query->select('id','name');
},'orders','orderDetails','orders.pickup'])->where('order_id',210)->whereIn("select max(id) from order_status_details group by `order_detail_id`")->get()->toArray();
Please or to participate in this conversation.