Authenticate.php 676 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\Http\Middleware;
  3. use Closure;
  4. use Illuminate\Support\Facades\Auth;
  5. class Authenticate
  6. {
  7. /**
  8. * Handle an incoming request.
  9. *
  10. * @param \Illuminate\Http\Request $request
  11. * @param \Closure $next
  12. * @param string|null $guard
  13. * @return mixed
  14. */
  15. public function handle($request, Closure $next, $guard = null)
  16. {
  17. if (Auth::guard($guard)->guest()) {
  18. if ($request->ajax() || $request->wantsJson()) {
  19. return response('Unauthorized.', 401);
  20. } else {
  21. return redirect()->guest('login');
  22. }
  23. }
  24. return $next($request);
  25. }
  26. }