i think you should try like this
$query = Employee::whereBetween('demo', array($bcs, $fcs));
$sum = $query->sum('bccs');
$ventas = $query->orderBy('demo', 'DSC')->orderBy('bcvd', 'ASC')->paginate();
Guys iam working with project.
i have given pagination and made to view.blade.
i also add the total values in a single field and passed to view.blade that is sum('amount') where amount is column name in my table.
My problem is the sum of the values are displayed page wise in the view.blade
i need the grand total must be displayed in the end of the page thats enough.
that is if i have 10 records and give pagination(5) then for the first five records the total is displayed in the first page and the next five records total is displayed in the second page.. i need to display the grand total of all the 10 records and must be displayed in the last page.
because the user needs to add the first page total and second page total to get the grand total
So kindly some one suggest an idea please??
this is my controller
public function index()
{
$exs = Excess_milk::orderBy('created_at','desc')->paginate(5);
return view('Excess_milk.view', [
'exs' => $exs,
'no_of_litre_total' => $exs->sum('no_of_litre')
]);
}
this is my screen shots
Page 1 Refer: https://imgur.com/XiWhGA9
Page 2 refer : https://imgur.com/IPzeJ2F
kindly someone help to rectify this
You can conditionally pass data to the view by using view::share
$exs = Excess_milk::orderBy('created_at','desc')->paginate(5);
if($exs->lastPage() == $exs->currentPage())
{
View::share('grandTotal', $exs->sum('no_of_litre'));
}
return view('Excess_milk.view', [
'exs' => $exs
]);
but your total is wrong. Here you only add the rows in the paginated data, but you need to run a new query summing all the records.
Please or to participate in this conversation.