Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Sum of a Laravel Datatable column using Yajra Datatable

I want to have the summation of a column and want to show on the datable footer. I tried to pass the summation of the attribute from the Controller, but it is giving a 500 Error. Please, anyone, share me the code for taking out a sum of an attribute and show in the Datatable Footer.

return datatables()->of($query)->make('false')
                ->with('total_amount', $query->sum('amount'));
like image 811
PRAMIT PAUL Avatar asked Dec 05 '25 14:12

PRAMIT PAUL


1 Answers

Following code block may help you:

->with('total', function() use ($query) {
     return $query->sum('amount');
})
like image 147
Muhammad Nadeem Avatar answered Dec 08 '25 06:12

Muhammad Nadeem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!