laravellaravel-5eloquentlaravel-8

error add money from all records - count()


i need to add up all the money in the column "ingresos".

error: Property [presupuesto] does not exist on this collection instance.

used the variable : {{ $contador->presupuesto->count() }}

database:

enter image description here

controller:

public function contador(){
    if (Auth::guest()) 
        return redirect('/login');

    $contador = \App\Models\Registro::All();
    return view('contador',compact('contador'));   
}

I need to add the income


Solution

  • You count the values, but you have to add them . To calculate the sum of values, use:

    $contador->sum('presupuesto');