calculate values in a view


Hi, I have a view in which I filter students per month.

And I have some doubts:

1) The most important thing is that I calculate the total number of students enrolled and that I add the amounts of the selected month  When I make a dd ($ registration) in my controller it shows me the following

LengthAwarePaginator {#411 ▼
  #total: 5
  #lastPage: 1
  #items: Collection {#413 ▶}
  #perPage: 10
  #currentPage: 1
  #path: "http://localhost:8000/matriculas/reportes"
  #query: []
  #fragment: null
  #pageName: "page"

How can I show that #total in the view, and how can I add the amounts and show them down ?? Help please.

My controller

public function reportes(Request $request)
    $matriculas = Matricula::search($request->fecha)->orderBy('created_at','DSC')->paginate(10);
    return view('matriculas/reportes')->with('matriculas',$matriculas);

and the view


	{!! Form::open(['URL' => 'matriculas/reportes', 'method' => 'GET', 'class' => 'navbar-form pull-left']) !!}
			{!! Form::label('fecha','Mes ')!!}
	    	<select name="fecha">
	    	  <option value="0">Seleccione....</option>	
			  <option value="1">Enero</option>
			  <option value="2">Febrero</option>
			  <option value="3">Marzo</option>
			  <option value="4">Abril</option>
			  <option value="5">Mayo</option>
			  <option value="6">Junio</option>
			  <option value="7">Julio</option>
			  <option value="8">Agosto</option>
			  <option value="9">Septiembre</option>
			  <option value="10">Octubre</option>
			  <option value="11">Noviembre</option>
			  <option value="12">Diciembre</option>
		<button type="submit" class="btn btn-primary">Buscar</button>
	{!! Form::close() !!}<br><br><br>


<div class="panel panel-primary">
<table class="table table-bordered">
			@foreach ($matriculas as $m)
					<td>{{Carbon\Carbon::parse($m->fecha)->format('d-m-Y') }}</td>
					<td>{{ $m->alumno->rut }}</td>
					<td>{{ $m->estado}}</td>
					<td>$ {{ $m->monto }}</td>
					<td><a href="{{route('', $m->id)}}" class="btn btn-info" ><span class="fa fa-eye" aria-hidden="true"></span></a></td>



				<div class="panel-body">
					<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12"">
						<div class="form-group">
							{!! Form::label('', '') !!}
					<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12"">
						<div class="form-group">
							{!! Form::label('Alumnos Matriculados', 'Alumnos Matriculados') !!}
							{!! Form::text('n1', null, array('class' => 'form-control')) !!}
					<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12"">
						<div class="form-group">
							{!! Form::label('Total', 'Total') !!}
							{!! Form::text('Total', null, array('class' => 'form-control')) !!}
asked by Edgardo Escobar 03.04.2017 в 01:39

1 answer


To obtain the count of records, use the count() method in the collection:

$alumnos = $matriculas->count();


To get the sum of the amounts, use the sum() method in the monto property of the collection:

$total = $matriculas->sum('monto');


answered by 03.04.2017 / 02:15