1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
-
- namespace App\Http\Middleware;
-
- use Closure;
-
- class SetDept
- {
- /**
- * Sets the department session variable to the desired department id or the default if none is set.
- *
- * @param \Illuminate\Http\Request $request
- * @param \Closure $next
- * @return mixed
- */
- public function handle($request, Closure $next)
- {
- // dump($request);
- if ($request->has('f')) {
- $data = $request->validate(['f' => 'regex:/[df]/']);
- $request->session()->put('filter', $data['f']);
- }
- if ($request->has('fclt')) {
- $data = $request->validate(['fclt' => 'integer|exists:faculties,id']);
- $request->session()->put('faculty', $data['fclt']);
- }
- if ($request->has('dept')) {
- $data = $request->validate(['dept' => 'integer|exists:departments,id']);
- $request->session()->put('department', $data['dept']);
- }
- if (!$request->session()->has('filter')) {
- $request->session()->put('filter', 'd');
- }
- if (!$request->session()->has('department')) {
- $default_dept_id = \App\Department::where('name', '=', 'BIOL')->first()->id;
- $request->session()->put('department', $default_dept_id);
- }
- // dump($request->session());
- return $next($request);
- }
- }
|