From 26bdfee839f4b8fb18beb1a9770fc758ad20c267 Mon Sep 17 00:00:00 2001 From: Mateja Date: Mon, 16 Nov 2020 20:15:43 +0100 Subject: AJAX filtering reservations on admin panel... --- app/Http/Controllers/ReservationsController.php | 37 +++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/Http/Controllers/ReservationsController.php b/app/Http/Controllers/ReservationsController.php index b347409..2a46343 100644 --- a/app/Http/Controllers/ReservationsController.php +++ b/app/Http/Controllers/ReservationsController.php @@ -128,8 +128,41 @@ class ReservationsController extends Controller // Administration public function edit(Request $request) { - $data = Reservation::orderBy('id', 'desc')->get(); - return view('pages.reservations', compact('data')); + if ($request->isMethod('post')) { + + $request->validate([ + 'call-sign' => 'required|alphanum' + ]); + + if ($request->input('call-sign') == 'all') { + $activities = Reservation::orderBy('id', 'desc') + ->get() + ->toArray(); + $data = [ + 'status' => 'OK', + 'data' => $activities + ]; + + return response($data); + } else { + $activities = Reservation::where('specialCall', $request->input('call-sign')) + ->orderBy('id', 'desc') + ->get() + ->toArray(); + $data = [ + 'status' => 'OK', + 'data' => $activities + ]; + + return response($data); + } + + } + else { + //$data = Reservation::orderBy('id', 'desc')->get(); + $signs = SpecialCall::all(); + return view('pages.reservations', compact('signs')); + } } public function update(Request $request) -- cgit v1.2.3