RedirectIfAuthenticated.php 877 B

1234567891011121314151617181920212223242526272829303132
  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(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
  14. * @param string|null ...$guards
  15. * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
  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. }