If you are on L8 or L9 you can use the HasOneOfMany relationship to get the last delivery on each load and then filter from there?
https://laravel.com/docs/8.x/eloquent-relationships#has-one-of-many
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I've Tables like , 1.Loads -> id , name , created_at 2.Deliveries -> id , load_id , date Each load can have multiple deliveries, Now i need to get the results of all loads delivery ends between from , to. This where between should apply on last deliver of a load.
public function scopeDateFilter($query, $from, $to, $feild)
{
$from = $from->startOfDay();
$to = $to->endOfDay();
$query->whereBetween($feild, [$from, $to]);
}
The above one is applying for all deliveries , instead of this i need to apply this where condition only on last delivery.
Please or to participate in this conversation.