Sin descripción

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Http\Middleware;
  3. use Closure;
  4. class SetDept
  5. {
  6. /**
  7. * Sets the department session variable to the desired department id or the default if none is set.
  8. *
  9. * @param \Illuminate\Http\Request $request
  10. * @param \Closure $next
  11. * @return mixed
  12. */
  13. public function handle($request, Closure $next)
  14. {
  15. // dump($request);
  16. if ($request->has('f')) {
  17. $data = $request->validate(['f' => 'regex:/[df]/']);
  18. $request->session()->put('filter', $data['f']);
  19. }
  20. if ($request->has('fclt')) {
  21. $data = $request->validate(['fclt' => 'integer|exists:faculties,id']);
  22. $request->session()->put('faculty', $data['fclt']);
  23. }
  24. if ($request->has('dept')) {
  25. $data = $request->validate(['dept' => 'integer|exists:departments,id']);
  26. $request->session()->put('department', $data['dept']);
  27. }
  28. if (!$request->session()->has('filter')) {
  29. $request->session()->put('filter', 'd');
  30. }
  31. if (!$request->session()->has('department')) {
  32. $default_dept_id = \App\Department::where('name', '=', 'BIOL')->first()->id;
  33. $request->session()->put('department', $default_dept_id);
  34. }
  35. // dump($request->session());
  36. return $next($request);
  37. }
  38. }