mykelcodex
1 week ago

Sum column

Posted 1 week ago by mykelcodex

Hey guys,

i have this code in my controller which displays the total amount of product price(weekly)


$weekly = Transaction::where('user_id',$id)->orderBy('created_at','desc')->get()->groupBy(function($date) {
             return Carbon::parse($date->created_at)->format('W');
             })->map(function ($row) {
                 return $row->sum('product_price');
             });

i also have this which displays the transactions(weekly)


$weekly = Transaction::where('user_id',$id)->orderBy('created_at','desc')->get()->groupBy(function($date) {
             return Carbon::parse($date->created_at)->format('W');
             });

i want to display the weekly transactions alongside the total of the product price(weekly). Please how do i do this?

Please sign in or create an account to participate in this conversation.