[8.x] Multiple guards for RedirectIfAuthenticated (#5329)

* Update RedirectIfAuthenticated.php

allow the middleware to have the same behavior as https://laravel.com/api/5.8/Illuminate/Auth/Middleware/Authenticate.html#method_authenticate

so now the guest middleware have the same footprint as auth ex.`guest:web,admin` instead of creating multiple lines to support different guards.

* Update RedirectIfAuthenticated.php
This commit is contained in:
Muah 2020-06-29 17:21:36 +02:00 committed by GitHub
parent 6ca2ecacea
commit adb7eacf9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 4 deletions

View File

@ -16,10 +16,18 @@ class RedirectIfAuthenticated
* @param string|null $guard * @param string|null $guard
* @return mixed * @return mixed
*/ */
public function handle($request, Closure $next, $guard = null) public function handle($request, Closure $next, ...$guards)
{ {
return Auth::guard($guard)->check() if (empty($guards)) {
? redirect(RouteServiceProvider::HOME) $guards = [null];
: $next($request); }
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect(RouteServiceProvider::HOME);
}
}
return $next($request);
} }
} }