I am working on an app that receives 10 to 13 data and they are saved in a table of my BD, I need to add that data and that sum is saved in another field of the table, I am using Laravel 5.5.
this is the driver:
public function show($id)
{
//fechas ingresadas de otra vista
$fecha1 = DB::table('fechas')->pluck('fecha_inicio')->all();
$fecha2 = DB::table('fechas')->pluck('fecha_fin')->all();
//fechas convertidas a string
$fecha1 = implode($fecha1);
$fecha2 = implode($fecha2);
//las vuelvo string de carbon
$primer_dia = (new Carbon($fecha1))->toDateString();
$ultimo_dia = (new Carbon($fecha2))->toDateString();
//query
$consumes = consume::where('user_id', $id)
->whereBetween('created_at',[$primer_dia,$ultimo_dia])
->get();
//vista
return view('user.consumo.show', [
'consumes'=>$consumes,
'fecha1' =>$fecha1,
'fecha2' =>$fecha2,
]);
}
Is it done by counting or by date? I receive suggestions.