From aed493eb95bf660145003f024434296c91d1c8c3 Mon Sep 17 00:00:00 2001 From: Mateja Date: Mon, 16 Nov 2020 18:18:19 +0100 Subject: Validate from and to date on reserve from. Copy activities.js to reservations.js --- app/Http/Controllers/ReservationsController.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app') diff --git a/app/Http/Controllers/ReservationsController.php b/app/Http/Controllers/ReservationsController.php index 1865f46..249d18a 100644 --- a/app/Http/Controllers/ReservationsController.php +++ b/app/Http/Controllers/ReservationsController.php @@ -92,6 +92,14 @@ class ReservationsController extends Controller $validator = Validator::make($request->all(), $rules, $messages); + $validator->after(function ($validator) use ($request) { + $fromStamp = strtotime($request->sdate . ' ' . $request->stime); + $toStamp = strtotime($request->edate . ' ' . $request->etime); + if (!($fromStamp < $toStamp)) { + $validator->errors()->add('time', 'FROM time and date needs to be before TO time and date.'); + } + }); + if ($validator->fails()) { return Redirect::back() ->withErrors($validator) -- cgit v1.2.3