Authenticate.php 751 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. }