PRAMIT PAUL
PRAMIT PAUL

Reputation: 114

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

Upvotes: 3

Views: 6531

Answers (1)

Muhammad Nadeem
Muhammad Nadeem

Reputation: 181

Following code block may help you:

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

Upvotes: 4

Related Questions