Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MooseSaid's avatar

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?

0 likes
7 replies
Sinnbeck's avatar

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

1 like
MooseSaid's avatar

@Sinnbeck that's the problem it's the same page. I have this main cart component page, in this page the user can see their items and click on 'shipping details' button and this will hide the cart items component and show the address form component instead (using v-if). Then there is another button after completing the address form which sends a request to a route which validates the form input and what I want here is passing the form input data to the parent component so that I can submit it later along with the ordet AFTER the payment gets confirmed.

To summarize, all I need is a way to pass the data to the parent component again in order to use it in the next step of the checkout process.

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@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

1 like
Sinnbeck's avatar

You could for instance set a flag in session in the post request, and pass more data based on if it's set in the get request

1 like
MooseSaid's avatar

@Sinnbeck but shouldn't Inertia::share make the data I'm sharing available to all components? Why can't I reach it at all? Am i using it wrong?

Sinnbeck's avatar

@MooseSaid you should use it in the get request.

You share it for the current request, but you need it for the next request

1 like
Sinnbeck's avatar

Thinking of it like a regular blade request and it might be easier?

1 like

Please or to participate in this conversation.