Nenhuma Descrição

Authenticate.php 751B

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