2023年4月


class HandleInertiaRequests extends Middleware
{
    public function handle(Request $request, Closure $next)
    {
        $response =  parent::handle($request, $next);
        if($response->isRedirection()) {
            $redirectTo = $response->headers->get('Location');
            $host = data_get(parse_url(config('app.url')), 'host');
            Log::debug('redirect to: '. $redirectTo);
            $redirectHost = data_get(parse_url($redirectTo), 'host');
            if($host !== $redirectHost) {
                return Inertia::location($redirectTo);
            }
        }
        return $response;
    }
}