laraveldatatableyajra-datatable

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'));

Solution

  • Following code block may help you:

    ->with('total', function() use ($query) {
         return $query->sum('amount');
    })