has('setdept')) { $data = $request->validate(['setdept' => 'integer|exists:departments,id']); $request->session()->put('department', $data['setdept']); } if (!$request->session()->has('department')) { $default_dept_id = \App\Department::whereNull('name')->first()->id; $request->session()->put('department', $default_dept_id); } // dump($request->session()->get('department')); return $next($request); } }