1234567891011121314151617181920212223242526272829 |
- <?php
-
- namespace App\Http\Middleware;
-
- use Closure;
-
- class SetDept
- {
-
-
- 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);
- }
-
- return $next($request);
- }
- }
|