Browse Source

Merge pull request #4904 from Te7a-Houdini/modify-redirect-if-auth-middleware-to-allow-multiple-guards

[5.8] Modify RedirectIfAuthenticated middleware to accept multiple guards
Taylor Otwell 5 years ago
parent
commit
2d2c089a4a
1 changed files with 6 additions and 4 deletions
  1. 6 4
      app/Http/Middleware/RedirectIfAuthenticated.php

+ 6 - 4
app/Http/Middleware/RedirectIfAuthenticated.php

@@ -12,13 +12,15 @@ class RedirectIfAuthenticated
      *
      * @param  \Illuminate\Http\Request  $request
      * @param  \Closure  $next
-     * @param  string|null  $guard
+     * @param  string[]  ...$guards
      * @return mixed
      */
-    public function handle($request, Closure $next, $guard = null)
+    public function handle($request, Closure $next, ...$guards)
     {
-        if (Auth::guard($guard)->check()) {
-            return redirect('/home');
+        foreach ($guards as $guard) {
+            if (Auth::guard($guard)->check()) {
+                return redirect('/home');
+            }
         }
 
         return $next($request);