From cddef1ffc9cb204d87299cea7e9f2de0cf6e58c3 Mon Sep 17 00:00:00 2001 From: Mateja Date: Fri, 13 Nov 2020 01:47:38 +0100 Subject: Work on activities... --- app/Http/Controllers/ReservationsController.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'app/Http/Controllers/ReservationsController.php') diff --git a/app/Http/Controllers/ReservationsController.php b/app/Http/Controllers/ReservationsController.php index d3b141e..141dbc4 100644 --- a/app/Http/Controllers/ReservationsController.php +++ b/app/Http/Controllers/ReservationsController.php @@ -11,20 +11,39 @@ use Illuminate\Support\Facades\Redirect; use App\Models\Reservation; use App\Models\SpecialCall; +use function response; class ReservationsController extends Controller { public function index(Request $request) { - $activities = Reservation::where('approved', '1')->get(); //$activities = Reservation::addSelect([ //'specialCall' => SpecialCall::select('sign') ////->whereColumn('reservations.specialCall', 'special_calls.id') //->whereColumn('specialCall', 'id') //->limit(1) //])->get(); - - return view('pages.activities', compact('activities')); + if ($request->isMethod('post')) { + + $request->validate([ + 'call-sign' => 'required|alphanum' + ]); + + if ($request->input('call-sign') == 'all') { + $activities = Reservation::where('approved', '1')->get(); + + return response()->json($activities); + } else { + $activities = Reservation::whereColumn('approved', '1') + ->whereColumn('specialCall', $request->input('call-sign')) + ->get(); + + return response()->json($activities); + } + } else if ($request->isMethod('get')) { + $signs = SpecialCall::all(); + return view('pages.activities', compact('signs')); + } } public function create(Request $request) -- cgit v1.2.3