input('classes_code'); $classes_code_from_session = session()->get('CLASSES_CODE'); $classes_id = session()->get('CLASSES_ID'); $classes = Classes::find($classes_id); if(!$classes) { return redirect('home'); } else { if ($classes_code_from_request != $classes_code_from_session) { return redirect('home'); } else { $user_id = Subject::where('id', $classes->subject_id)->first()->user_id; if (!$user_id || $user_id != Auth::id()) { return redirect('home'); } } } $request->attributes->add(['classes_id' => $classes->id]); return $next($request); } }