But you are redirecting away? You are sharing the data, and instantly leave the "page". Pass it to the view on the page you redirect to
Inertia Manual Share State Lazily Inside Controller not Working!!
I'm going crazy because of this one, I have this address form in a very nested component and a route to validate the form input data. In the controller, I want to return back to the same page but share the form data to be able to fetch it in a parent component. I'm trying to follow Inertia DOCs to lazily share the data to be available to all components but for some reason this isn't working!
1- I'm submitting the form:
const submitAddressCheck = () => {
shippingDetailsForm.post(
route("cart.checkaddress", [props.webshop_slug]),
{}
);
};
2- The form gets validated as expected but it doesn't share the data globally to all components. CartController.php
public function checkaddress(StoreAddressCheckRequest $request)
{
Inertia::share(
'testing',
fn ($request) => $request
? $request
: null
);
return redirect()->back();
}
Once I submit the form it gets validated and that's it, no new props passed, the data isn't being shared to my parent component or anything. Am I missing something?
@MooseSaid in inertia there is just one layer. You can extract the data from any child component with usePage. So each page need to pass the full data needed to the "view". So you need to either pass it down on the page you were on, or redirect to a new page that can show it all there.
You can also use preserveState to keep data after a post/redirect back
Please or to participate in this conversation.