2015-07-08 03:34:58 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
2020-02-25 16:05:35 -05:00
|
|
|
use App\Providers\RouteServiceProvider;
|
2015-07-08 03:34:58 -04:00
|
|
|
use Closure;
|
2020-12-09 16:00:01 -05:00
|
|
|
use Illuminate\Http\Request;
|
2016-01-03 23:55:13 -05:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2023-03-13 17:33:19 -04:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2015-07-08 03:34:58 -04:00
|
|
|
|
|
|
|
class RedirectIfAuthenticated
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
2023-03-13 17:33:19 -04:00
|
|
|
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
2015-07-08 03:34:58 -04:00
|
|
|
*/
|
2023-03-13 17:33:19 -04:00
|
|
|
public function handle(Request $request, Closure $next, string ...$guards): Response
|
2015-07-08 03:34:58 -04:00
|
|
|
{
|
2020-12-09 16:00:01 -05:00
|
|
|
$guards = empty($guards) ? [null] : $guards;
|
|
|
|
|
|
|
|
foreach ($guards as $guard) {
|
|
|
|
if (Auth::guard($guard)->check()) {
|
|
|
|
return redirect(RouteServiceProvider::HOME);
|
|
|
|
}
|
2015-07-08 03:34:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|