My beer compendium
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
734 B

3 years ago
  1. <?php
  2. namespace App\Http\Middleware;
  3. use App\Providers\RouteServiceProvider;
  4. use Closure;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Auth;
  7. class RedirectIfAuthenticated
  8. {
  9. /**
  10. * Handle an incoming request.
  11. *
  12. * @param \Illuminate\Http\Request $request
  13. * @param \Closure $next
  14. * @param string|null ...$guards
  15. * @return mixed
  16. */
  17. public function handle(Request $request, Closure $next, ...$guards)
  18. {
  19. $guards = empty($guards) ? [null] : $guards;
  20. foreach ($guards as $guard) {
  21. if (Auth::guard($guard)->check()) {
  22. return redirect(RouteServiceProvider::HOME);
  23. }
  24. }
  25. return $next($request);
  26. }
  27. }