diff options
Diffstat (limited to 'app/Http/Middleware/RedirectIfAuthenticated.php')
-rw-r--r-- | app/Http/Middleware/RedirectIfAuthenticated.php | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php new file mode 100644 index 0000000..afc78c4 --- /dev/null +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -0,0 +1,30 @@ +<?php + +namespace App\Http\Middleware; + +use App\Providers\RouteServiceProvider; +use Closure; +use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; +use Symfony\Component\HttpFoundation\Response; + +class RedirectIfAuthenticated +{ + /** + * Handle an incoming request. + * + * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next + */ + public function handle(Request $request, Closure $next, string ...$guards): Response + { + $guards = empty($guards) ? [null] : $guards; + + foreach ($guards as $guard) { + if (Auth::guard($guard)->check()) { + return redirect(RouteServiceProvider::HOME); + } + } + + return $next($request); + } +} |