From bdcf6113a19f06414dd4be9566036c437441ad5f Mon Sep 17 00:00:00 2001 From: Laeng Date: Wed, 7 Aug 2024 20:20:20 +0900 Subject: [PATCH] Update EditorController.php --- .../App/Mission/EditorController.php | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/App/Mission/EditorController.php b/app/Http/Controllers/App/Mission/EditorController.php index a6a578d..4873fd3 100644 --- a/app/Http/Controllers/App/Mission/EditorController.php +++ b/app/Http/Controllers/App/Mission/EditorController.php @@ -118,13 +118,19 @@ public function create(Request $request, SurveyServiceContract $surveyService, N } $typeKorean = MissionType::getKoreanNames()[$type]; + $data = null; + try { - $date = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', "{$request->get('date')} {$request->get('time')}"); + $dateString = $request->get('date') . ' ' . $request->get('time'); + $date = \Carbon\Carbon::parse($dateString); + + if (!$date->isValid()) { + throw new \Exception('Invalid date/time format'); + } } catch (\Exception $e) { - throw new \Exception('Invalid data/time format', 422); + throw new \Exception('Invalid date/time format', 422); } - if ($date->isPast()) { throw new \Exception('DATE OLD', 422); @@ -209,7 +215,18 @@ public function update(Request $request): JsonResponse } $typeKorean = MissionType::getKoreanNames()[$type]; - $date = \Carbon\Carbon::createFromFormat('Y-m-d H:i', "{$request->get('date')} {$request->get('time')}"); + $data = null; + + try { + $dateString = $request->get('date') . ' ' . $request->get('time'); + $date = \Carbon\Carbon::parse($dateString); + + if (!$date->isValid()) { + throw new \Exception('Invalid date/time format'); + } + } catch (\Exception $e) { + throw new \Exception('Invalid date/time format', 422); + } if ($date->isPast()) {