Skip to content
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

Redirect back when an Inertia response is empty (customizable) #350

Merged
merged 2 commits into from
Jan 20, 2022

Conversation

claudiodekker
Copy link
Member

@claudiodekker claudiodekker commented Jan 14, 2022

This PR automatically converts empty Inertia controller/action responses to Inertia redirects back.

This prevents the need to manually specify the redirect()->back(); at the bottom of all of your actions, keeping your code a little bit simpler. Do note that this doesn't mean you have to stop redirecting back manually if you prefer to have a consistent return value, but it does provide the option to omit it for those who'd rather not do it everywhere.

This behavior is customizable by customizing the onEmptyResponse method that's now part of the Middleware.
You can, for example, render an error page of your own using Inertia::render(), or throw an exception.

@claudiodekker claudiodekker changed the title Automatically redirect no-response/empty Inertia requests to redirects back Automatically convert no-response/empty Inertia requests to redirects back Jan 14, 2022
@innocenzi
Copy link
Contributor

This looks nice and would certainly improve the DX.

As discussed on Discord: I suggest adding a property check (or something else) to allow for disabling the feature, to account for edge cases or other instances where this could be not needed.

@claudiodekker
Copy link
Member Author

claudiodekker commented Jan 14, 2022

Alright, after lots of discussion in Discord I'm going to tweak this one a little.

@claudiodekker
Copy link
Member Author

Updated. Also updated the original description.

@innocenzi
Copy link
Contributor

That's great, good changes 👍

@claudiodekker claudiodekker changed the title Automatically convert no-response/empty Inertia requests to redirects back Redirect back by default when an Inertia response is empty (middleware-customizable) Jan 15, 2022
@claudiodekker claudiodekker changed the title Redirect back by default when an Inertia response is empty (middleware-customizable) Redirect back by default when an Inertia response is empty (customizable) Jan 15, 2022
@claudiodekker claudiodekker changed the title Redirect back by default when an Inertia response is empty (customizable) Redirect back when an Inertia response is empty (middleware customizable) Jan 15, 2022
@claudiodekker claudiodekker changed the title Redirect back when an Inertia response is empty (middleware customizable) Redirect back when an Inertia response is empty (customizable) Jan 15, 2022
@claudiodekker claudiodekker merged commit 8226ee4 into master Jan 20, 2022
@claudiodekker claudiodekker deleted the allow-empty-response branch January 20, 2022 13: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