Home > Back-end >  Laravel get SUM Of columns in all pages in paginator
Laravel get SUM Of columns in all pages in paginator

Time:01-16

i have a column in my table it name is AccountBalance i use laravel paginator with 30 rows per page when i use $paginator->sum('AccountBalance') it return Just sum of 30 rows in current page i want to get sum of AccountBalance column in all pages

CodePudding user response:

Use this code

$totalSum = YourModel::select('AccountBalance')->sum('AccountBalance');
$paginator = YourModel::paginate(30);

CodePudding user response:

You can do sum before, paginate.

$balance = AccountBalance::all();
$total = $balance->sum('total');
$paginator = $balance->paginate(100);

return view("your.view",compact('total','paginator');
  • Related