text4u
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.

RedirectIfAuthenticated.php 760B

123456789101112131415161718192021222324252627282930
  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. use Symfony\Component\HttpFoundation\Response;
  8. class RedirectIfAuthenticated
  9. {
  10. /**
  11. * Handle an incoming request.
  12. *
  13. * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
  14. */
  15. public function handle(Request $request, Closure $next, string ...$guards): Response
  16. {
  17. $guards = empty($guards) ? [null] : $guards;
  18. foreach ($guards as $guard) {
  19. if (Auth::guard($guard)->check()) {
  20. return redirect(RouteServiceProvider::HOME);
  21. }
  22. }
  23. return $next($request);
  24. }
  25. }