1234567891011121314151617181920212223242526272829 |
- <?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)
- {
- if ($request->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);
- }
- }
|