Authenticated.php 819 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php namespace App\Http\Middleware;
  2. use Closure;
  3. use Illuminate\Contracts\Auth\Guard;
  4. use Illuminate\Contracts\Routing\Middleware;
  5. class Authenticated implements Middleware {
  6. /**
  7. * The Guard implementation.
  8. *
  9. * @var Guard
  10. */
  11. protected $auth;
  12. /**
  13. * Create a new filter instance.
  14. *
  15. * @param Guard $auth
  16. * @return void
  17. */
  18. public function __construct(Guard $auth)
  19. {
  20. $this->auth = $auth;
  21. }
  22. /**
  23. * Handle an incoming request.
  24. *
  25. * @param \Illuminate\Http\Request $request
  26. * @param \Closure $next
  27. * @return mixed
  28. */
  29. public function handle($request, Closure $next)
  30. {
  31. if ($this->auth->guest())
  32. {
  33. if ($request->ajax())
  34. {
  35. return response('Unauthorized.', 401);
  36. }
  37. else
  38. {
  39. return redirect()->guest('auth/login');
  40. }
  41. }
  42. return $next($request);
  43. }
  44. }