diff --git a/app/Http/Controllers/VehicleController.php b/app/Http/Controllers/VehicleController.php index a3f37de..9ecd9af 100644 --- a/app/Http/Controllers/VehicleController.php +++ b/app/Http/Controllers/VehicleController.php @@ -55,20 +55,6 @@ class VehicleController extends Controller ], 404); } - // $expectedKeys = ['vehicle_number','entry_time','exit_time','duration','type']; - - // $requestKeys = array_keys($request->all()); - - // sort($expectedKeys); - // sort($requestKeys); - - // if ($expectedKeys != $requestKeys) { - // return response()->json([ - // 'status' => 'ERROR', - // 'status_description' => 'Send proper valid JSON structure' - // ], 400); - // } - $plantId = $plantCod->id; $data = $request->all(); @@ -140,20 +126,27 @@ class VehicleController extends Controller ], 404); } - $entryTime = $entryTimeRaw - ? Carbon::createFromFormat('d/m/Y h:i:s A', $entryTimeRaw) - : null; + if(!empty($entryTimeRaw)){ + $entryTime = $entryTimeRaw + ? Carbon::createFromFormat('d/m/Y h:i:s A', $entryTimeRaw) + : null; + } - $exitTime = $exitTimeRaw + $exitTime = null; + + if(!empty($exitTimeRaw)){ + + $exitTime = $exitTimeRaw ? Carbon::createFromFormat('d/m/Y h:i:s A', $exitTimeRaw) : null; + } $record = VehicleEntry::insert([ 'plant_id' => $plantId, 'vehicle_number' => $vehicleNo, 'entry_time' => $entryTime, - 'exit_time' => $exitTime, - 'duration' => $duration, + 'exit_time' => $exitTime ?? null, + 'duration' => $duration ?: null, 'type' => $type, 'created_at' => now(), 'updated_at' => now(),