Вход Регистрация
Файл: vendor/laravel/framework/src/Illuminate/Auth/Middleware/RedirectIfAuthenticated.php
Строк: 67
<?php

namespace IlluminateAuthMiddleware;

use 
Closure;
use 
IlluminateHttpRequest;
use 
IlluminateSupportFacadesAuth;
use 
IlluminateSupportFacadesRoute;
use 
SymfonyComponentHttpFoundationResponse;

class 
RedirectIfAuthenticated
{
    
/**
     * The callback that should be used to generate the authentication redirect path.
     *
     * @var callable|null
     */
    
protected static $redirectToCallback;

    
/**
     * Specify the guards for the middleware.
     *
     * @param  string  $guard
     * @param  string  $others
     * @return string
     */
    
public static function using($guard, ...$others)
    {
        return static::class.
':'.implode(',', [$guard, ...$others]);
    }

    
/**
     * Handle an incoming request.
     *
     * @param  Closure(IlluminateHttpRequest): (SymfonyComponentHttpFoundationResponse)  $next
     */
    
public function handle(Request $request, Closure $next, string ...$guards): Response
    
{
        
$guards = empty($guards) ? [null] : $guards;

        foreach (
$guards as $guard) {
            if (
Auth::guard($guard)->check()) {
                return 
redirect($this->redirectTo($request));
            }
        }

        return 
$next($request);
    }

    
/**
     * Get the path the user should be redirected to when they are authenticated.
     */
    
protected function redirectTo(Request $request): ?string
    
{
        return static::
$redirectToCallback
            
? call_user_func(static::$redirectToCallback, $request)
            : 
$this->defaultRedirectUri();
    }

    
/**
     * Get the default URI the user should be redirected to when they are authenticated.
     */
    
protected function defaultRedirectUri(): string
    
{
        foreach ([
'dashboard', 'home'] as $uri) {
            if (
Route::has($uri)) {
                return 
route($uri);
            }
        }

        
$routes = Route::getRoutes()->get('GET');

        foreach ([
'dashboard', 'home'] as $uri) {
            if (isset(
$routes[$uri])) {
                return 
'/'.$uri;
            }
        }

        return 
'/';
    }

    
/**
     * Specify the callback that should be used to generate the redirect path.
     *
     * @param  callable  $redirectToCallback
     * @return void
     */
    
public static function redirectUsing(callable $redirectToCallback)
    {
        static::
$redirectToCallback = $redirectToCallback;
    }
}
Онлайн: 1
Реклама