Skip to content

Allow URL override for response #499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

@rojtjo
Copy link
Contributor

rojtjo commented Feb 1, 2023

The thing I dislike about this is that you'd be required to manually call the toResponse method from your controller or middleware.

I would probably prefer a solution where you'd be able to just override a method on the HandleInertiaRequests middleware to define a resolver. This way there is no need to manually call the toResponse method and the framework can just handle the rest.

use Inertia\Middleware;

class HandleInertiaRequests extends Middleware
{
    public function urlResolver(Request $request): ?callable
    {
        return fn (Request $request) => 'https://inertiajs.com/'.$request->getRequestUri();
    }
}

I've prepared possible solution for this here: master...rojtjo:inertia-laravel:feature/url-override

@FrittenKeeZ
Copy link
Author

@rojtjo I like that method a lot - I initially thought about making a resolver on the response class itself, but it would basically be the same thing, as you had to call toResponse as well.

@FrittenKeeZ
Copy link
Author

@rojtjo would you consider making a PR with your changes?

@rojtjo
Copy link
Contributor

rojtjo commented Feb 10, 2023

Sure, no problem!

@FrittenKeeZ
Copy link
Author

Closing this in favor of #503 which works as expected

@FrittenKeeZ FrittenKeeZ deleted the feature/response-url-override branch February 10, 2023 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants