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

bwrigley's avatar

Inertia loading up a page within a page

I'm sure I'm missing something obvious in the Inertia docs here, but I'm really not sure how best to do this.

I have a simple forum that is accessed via a GET request to /feed

In my FeedController:

    public function index():  Response
    {

        return Inertia::render('Feed/Feed', [
            'posts' => fn() => Post::orderBy('updated_at', 'desc')
                                ->get(),
        ]);
    }

Straightforward. Now I want to add the functionality that the user can click on a Post which opens a lightbox and displays the Post fully and all of it's relationships etc which means making a request to the server.

My challenge is how to do this with Inertia without affecting the feed that sits behind the lightbox.

I can add a featured prop returned by the index() method which is initially null and then run a partial reload each time the user clicks a post

    public function index(Request $request):  Response
    {
        return Inertia::render('Feed/Feed', [
            'posts' => fn() => Post::orderBy('updated_at', 'desc')
                                ->get(),
			'featured' => fn() => $request->featured ? Post::find($request->featured) : null,
        ]);
    }

But this feels like a bodge to me: I now have a single method that needs to accept both GET and POST (assuming I want to hide the url). And to try and stick with SOLID principles I would prefer to have a show() method return the individual Post with relationships.

Any ideas on how to do this 'right'?

0 likes
8 replies
bwrigley's avatar

Thanks! I was hoping that this was something Inertia offered but I can make an axios request instead. Maybe a feature request.

wojakmcwagies's avatar

Basically, you have a page that has a table that contains a lot of data. And you want to click one of them, show a modal that contains more detailed content regarding that data, correct?

If so then you can create a modal (you can use Bootstrap modal or Tailwind modal, no need for package). Then use Inertia get method to a different controller method (your render is in index method, this one is in show method for example). And that's it.

I'm pretty sure this should work as my website is doing the same thing, even for the CRUD. So I basically display, create, update, and delete within a single page and with a single modal (yes, you can).

1 like
bwrigley's avatar

@wojakmcwagies that's exactly it thank you!

So can I ask how you manage to perform the Intertia get without redirecting away from the current page and without using partial reload, which obviously uses the same controller method that rendered the current page?

If I've understood the docs correctly, from the client side I essentially have router.visit() or its derivatives router.get() etc. These all seem to redirect to a new page.

Then from the server I see Inertia::render() which requires a Page as it's first argument where I just want to return some data.

Can you point me to the methods you are using please?

wojakmcwagies's avatar

@bwrigley First of all, I'm going to say that I use Inertia with Svelte, so my example is in Inertia Svelte version. Second, I can't exactly show you how I do it, as it's fine tuned for my company and I don't know if leaking the code is a good idea, plus it's bloated as hell so removing them to the basic form isn't easy. What I can give you is the alternative versions:

  1. Use Axios. Basically, you create a new method in your controller, create a route for that method, and use axios get method to reach that method in the controller. In the controller itself, you return JSON.

  2. This one is even easier as you don't need another method in your controller. When you return data in the index method, just put in the data that you wanted to show for the detailed modal too. So something like this in the Svelte page:

    function showDetailed(row) {
        $form.image = row.image;
        $form.system = row.system;

        isView = true;
        modal.show();
    }

When you loop through the table to display your data, you'll do something like this right?

                <tbody>
                    {#each $rows as row}
                        <tr>
                            <td>
                                <div role="button" on:click={showDetailed(row)}>
									{row.system}
								</div>
                            </td>
                        </tr>
                    {:else}
                        <tr class="position-static">
                            <td colspan="8">No data available in table</td>
                        </tr>
                    {/each}
                </tbody>

The code above is an illustration where you get the "row" parameter for the showDetailed modal.

bwrigley's avatar

@wojakmcwagies

Ah, if I understand correctly then I think that's similar to the solution I was using: I have a small composable that can perform axios requests and retrieve the data.

What I was hoping to find was an Inertia specific method that could essentially do the same without having to rerender the page. Much like how I suspect a partial reload must work under the hood.

Thanks for taking the time to share your code!

If I've understood it correctly, you load all the rows into memory beforehand and only show limited row data in your table. Then when the user clicks to have a detailed view, you show more of the row data. But all of the row detail is already in memory right? You don't make a new request for additional data at that point?

My situation is that when I first render the page I want my controller to only send a couple of fields to display e.g. just your row.system . Then when the user selects an item I want to go back to the server to get all the other data as well as relationships or in your case I would be requesting row.image to display.

wojakmcwagies's avatar

@bwrigley

If I've understood it correctly, you load all the rows into memory beforehand and only show limited row data in your table. Then when the user clicks to have a detailed view, you show more of the row data. But all of the row detail is already in memory right? You don't make a new request for additional data at that point?

Correct

My situation is that when I first render the page I want my controller to only send a couple of fields to display e.g. just your row.system .

Then you can use the first method. Since you're returning a plain JSON, it won't conflict with Inertia::render from your index method. You can imagine it like umm... when you delete a data, you might want to display a SweetAlert2 saying delete is success right? This is pretty much the same, except it's not only message but a data, and not SweetAlert2 but your own modal.

Please or to participate in this conversation.