pingcrm/app/Http/Middleware/RedirectIfAuthenticated.php

32 lines
699 B
PHP
Raw Normal View History

2019-03-05 18:10:11 -03:00
<?php
namespace App\Http\Middleware;
2020-07-29 11:37:19 -03:00
use App\Providers\RouteServiceProvider;
2019-03-05 18:10:11 -03:00
use Closure;
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
2020-09-08 19:45:49 -03:00
* @param string[]|null ...$guards
2019-03-05 18:10:11 -03:00
* @return mixed
*/
2020-09-08 19:45:49 -03:00
public function handle($request, Closure $next, ...$guards)
2019-03-05 18:10:11 -03:00
{
2020-09-08 19:45:49 -03:00
$guards = empty($guards) ? [null] : $guards;
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect(RouteServiceProvider::HOME);
}
2019-03-05 18:10:11 -03:00
}
return $next($request);
}
}