Authenticate.php 889 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php namespace App\Http\Middleware;
  2. use Closure;
  3. use Illuminate\Contracts\Auth\Guard;
  4. class Authenticate
  5. {
  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. if ($request->ajax()) {
  33. return response('Unauthorized.', 401);
  34. } else {
  35. return redirect()->guest('auth/login');
  36. }
  37. }
  38. return $next($request);
  39. }
  40. }