Files
ponzi/app/Http/Middleware/RedirectIfAuthenticated.php
Muah adb7eacf9e [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
2020-06-29 10:21:36 -05:00

34 lines
710 B
PHP

<?php
namespace App\Http\Middleware;
use App\Providers\RouteServiceProvider;
use Closure;
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, ...$guards)
{
if (empty($guards)) {
$guards = [null];
}
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect(RouteServiceProvider::HOME);
}
}
return $next($request);
}
}