Authenticate.php 911B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Http\Middleware;
  3. use Closure;
  4. use Illuminate\Contracts\Auth\Factory as Auth;
  5. class Authenticate
  6. {
  7. /**
  8. * The authentication guard factory instance.
  9. *
  10. * @var \Illuminate\Contracts\Auth\Factory
  11. */
  12. protected $auth;
  13. /**
  14. * Create a new middleware instance.
  15. *
  16. * @param \Illuminate\Contracts\Auth\Factory $auth
  17. * @return void
  18. */
  19. public function __construct(Auth $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. * @param string|null $guard
  29. * @return mixed
  30. */
  31. public function handle($request, Closure $next, $guard = null)
  32. {
  33. if ($this->auth->guard($guard)->guest()) {
  34. return response('Unauthorized.', 401);
  35. }
  36. return $next($request);
  37. }
  38. }