CheckForMaintenanceMode.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Http\Middleware;
  3. use Closure;
  4. use Auth;
  5. use Illuminate\Contracts\Foundation\Application;
  6. class CheckForMaintenanceMode
  7. {
  8. /**
  9. * The application implementation.
  10. *
  11. * @var \Illuminate\Contracts\Foundation\Application
  12. */
  13. protected $app;
  14. /**
  15. * The URIs that should be reachable while maintenance mode is enabled.
  16. *
  17. * @var array
  18. */
  19. protected $except = [
  20. '/admin*','/login','/logout', '/subcategories*', '/subsubcategories*', '/home_categories*', '/aiz-uploader*'
  21. ];
  22. /**
  23. * Create a new middleware instance.
  24. *
  25. * @param \Illuminate\Contracts\Foundation\Application $app
  26. * @return void
  27. */
  28. public function __construct(Application $app)
  29. {
  30. $this->app = $app;
  31. }
  32. /**
  33. * Handle an incoming request.
  34. *
  35. * @param \Illuminate\Http\Request $request
  36. * @param \Closure $next
  37. * @return mixed
  38. *
  39. * @throws \Symfony\Component\HttpKernel\Exception\HttpException
  40. */
  41. public function handle($request, Closure $next)
  42. {
  43. if ($this->app->isDownForMaintenance()){
  44. if((Auth::check() && Auth::user()->user_type == 'admin') || (Auth::check() && Auth::user()->user_type == 'staff') || $this->inExceptArray($request)) {
  45. return $next($request);
  46. }
  47. else {
  48. return abort(503);
  49. }
  50. }
  51. return $next($request);
  52. }
  53. /**
  54. * Determine if the request has a URI that should be accessible in maintenance mode.
  55. *
  56. * @param \Illuminate\Http\Request $request
  57. * @return bool
  58. */
  59. protected function inExceptArray($request)
  60. {
  61. foreach ($this->except as $except) {
  62. if ($except !== '/') {
  63. $except = trim($except, '/');
  64. }
  65. if ($request->fullUrlIs($except) || $request->is($except)) {
  66. return true;
  67. }
  68. }
  69. return false;
  70. }
  71. }