dzmaktaba

Code MixtPost

Dec 2nd, 2023
969
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Middleware;
  4.  
  5. use App\Providers\RouteServiceProvider;
  6. use Closure;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Facades\Auth;
  9. use Symfony\Component\HttpFoundation\Response;
  10.  
  11. class RedirectIfAuthenticated
  12. {
  13.     /**
  14.      * Handle an incoming request.
  15.      *
  16.      * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
  17.      */
  18.     public function handle(Request $request, Closure $next, string ...$guards): Response
  19.     {
  20.         $guards = empty($guards) ? [null] : $guards;
  21.  
  22.         foreach ($guards as $guard) {
  23.             if (Auth::guard($guard)->check()) {
  24.                 return redirect(RouteServiceProvider::HOME);
  25.             }
  26.         }
  27.  
  28.         return $next($request);
  29.     }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment