Alexmg86
Repos
12
Followers
8
Following
1

Laravel sum, min, max, avg columns in related model, sorting by relations and limit relations rows

73
5

Events

Sum on realtion

Hi, @hairullana try to add trait in order model and use something like this

$pl_orders = PackingListOrder::where('packing_list_id', $p1->id)
->with(['order' => function ($query) {
    $query->with(['customer', 'country', 'items'])
    ->withSum('items:picked,missing');
}])->get();
Created at 1 month ago
Created at 2 months ago