3 years ago

sum paginate

Posted 3 years ago by nicosli

Hi I have a table called 'ventas', i'm using paginate and i need to sum the colum 'monto', my question is ¿do need i to call first all() and then paginate()? i need to know the total of 'monto' colum in a date range, with paginate(10) i can only know the sum of 10 records

i'm trying this

$ventas = Venta::whereBetween('fecha_venta', array($fhInicio, $fhFin))->orderBy('fecha_venta', 'DSC')->orderBy('hora_venta', 'ASC');

$todo = $ventas->get();
$totalVenta = $todo->sum(function($todo){
return $todo->items->sum('monto');

$ventas = $ventas->paginate(10);

Thanks in advance.

Please sign in or create an account to participate in this conversation.