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

rafa-acioly's avatar

How can I retrieve data to be shown on a modal and preserve the page state?

I'm building an modal that will retrieve information to be displayed on the own modal, however, when I do a request all my page state is lost even if I set "preserveState" to true.

How can I send a GET request and preserve tha page state?

import { router } from '@inertiajs/vue3'

router.get(`/dashboard/products/store/${ storeSku.value }`, {
    preserveState: true,
    preserveScroll: true,
    only: ['data'],
    onSuccess: (data) => {
      console.log('-> response from findProductFromStore', data)
    },
    onError: (err) => {
      console.log('-> error from findProductFromStore', err)
    }
})

My Controller:

public function find(string $sku)
{
    $product = FindProductOnUserStore::run($sku);

    abort_unless($product, 404, 'could not find product on user store');

    return inertia('Product/Index', [
        'data' => $product
    ]);
}

I've tried using return inertia('Product/Index') and also return back()->with('data, $product)

0 likes
4 replies
Tray2's avatar

You can use an ajax call, either using the fetch api, axios, or something similar.

rafa-acioly's avatar

@Tray2 I've tried to call the /api route to retrieve a JSON but I got into a authentication problem, if the request pass through the "api" route I can't acess the authenticated session to retrieve the correct information.

rafa-acioly's avatar

@Tray2 Thank you, I got back to using axios, I was missing the APP_URL parameter when I deployed my application.

Please or to participate in this conversation.