* 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
34 lines
710 B
PHP
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);
|
|
}
|
|
}
|