Skip to content

Commit

Permalink
[8.x] Multiple guards for RedirectIfAuthenticated (#5329)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ctf0 committed Jun 29, 2020
1 parent 6ca2eca commit adb7eac
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@ class RedirectIfAuthenticated
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
public function handle($request, Closure $next, ...$guards)
{
return Auth::guard($guard)->check()
? redirect(RouteServiceProvider::HOME)
: $next($request);
if (empty($guards)) {
$guards = [null];
}

foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect(RouteServiceProvider::HOME);
}
}

return $next($request);
}
}

0 comments on commit adb7eac

Please sign in to comment.