Authenticate.php 889 B

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