Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| RedirectIfAuthenticated | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
72 | |
0.00% |
0 / 1 |
| handle | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
72 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Middleware; |
| 4 | |
| 5 | use Illuminate\Http\Request; |
| 6 | use Symfony\Component\HttpFoundation\Response; |
| 7 | |
| 8 | class RedirectIfAuthenticated |
| 9 | { |
| 10 | /** |
| 11 | * Handle an incoming request. |
| 12 | * |
| 13 | * @param \Illuminate\Http\Request $request |
| 14 | * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next |
| 15 | * @param string|null ...$guards |
| 16 | * @return \Symfony\Component\HttpFoundation\Response |
| 17 | * @throws \RuntimeException If guard is unhandled. |
| 18 | * @phpcs:disable Squiz.Commenting.FunctionComment.IncorrectTypeHint |
| 19 | */ |
| 20 | public function handle(Request $request, \Closure $next, ...$guards): Response |
| 21 | { |
| 22 | // phpcs:enable phpcs:disable |
| 23 | $guards = empty($guards) ? [null] : $guards; |
| 24 | |
| 25 | foreach ($guards as $guard) { |
| 26 | if (auth($guard)->check()) { |
| 27 | switch ($guard) { |
| 28 | case 'frontend': |
| 29 | return \redirect()->route('fo.homepage'); |
| 30 | case 'backend': |
| 31 | if (!$request->routeIs('bo.*')) { |
| 32 | continue; |
| 33 | } |
| 34 | return \redirect()->route('bo.dashboard'); |
| 35 | default: |
| 36 | throw new \RuntimeException("Unhandled guard `{$guard}` ."); |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | return $next($request); |
| 42 | } |
| 43 | } |