I am trying to calculate the average time between the column created_at and updated_at, but I am having problems with the foreach, since it only takes the last value I send it, and ignores all the others.
public function tiempo()
{
$creaciones = Deposito::where('autorizacion','=','1')->get();
$prome= count($creaciones);
foreach($creaciones as $creacion)
{
$timein = $creacion->created_at;
$timefn = $creacion->updated_at;
$dif = $timein->diffInMinutes($timefn);
$suma = $dif;
$pro = (int)$suma;
$tiempo = $pro/$prome;
}
return view('graficas.sucursales',compact('tiempo'));
}
They could tell me what I should do to go through all the results of the consultation.