diff --git a/app/Services/VehicleService.php b/app/Services/VehicleService.php index a811c8d..324a98c 100644 --- a/app/Services/VehicleService.php +++ b/app/Services/VehicleService.php @@ -119,13 +119,16 @@ public function listarVehiculosRobados(): array /** * Listar detecciones del día desde MySQL - * Muestra solo los últimos 10 registros por arco */ - public function listarDeteccionesDelDia(?string $fecha = null, ?int $arcoId = null, int $limit = 10): array + public function listarDeteccionesDelDia(?string $fecha = null, ?int $arcoId = null, int $segundos = 10): array { $fecha = $fecha ?? now()->format('Y-m-d'); - $query = DailyDetection::delDia($fecha); + // Calcular timestamp hace N segundos + $tiempoLimite = now()->subSeconds($segundos); + + $query = DailyDetection::delDia($fecha) + ->where('fecha_deteccion', '>=', $tiempoLimite); // Filtrar por arco si se especifica if ($arcoId !== null) { @@ -134,7 +137,6 @@ public function listarDeteccionesDelDia(?string $fecha = null, ?int $arcoId = nu $detecciones = $query ->orderBy('fecha_deteccion', 'desc') - ->limit($limit) ->get() ->map(function ($deteccion) { return [