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

bwrigley's avatar

Can I redirect a GET request to a POST request for Inertia partial reloads?

This feels like it's going to have an obvious answer but I'm not seeing one at present.

I'm using Vue with Inertia for my front end and I want to make use of the partial reload function.

I want users to be able to start their journey by visiting /feed which is obviously a GET request. It calls this method:

    public function index(Request $request):  Response
    {
        return Inertia::render('Feed/Feed', [
            'posts' => fn () =>  $this->getPostFeed(1),
            'users' => fn () => User::has('posts')->get()->keyBy('id'),
            'featured' => fn() => $request->featured ? $this->getFeatured($request->featured) : null
        ]);
    }

I then want users to be able to click on Post which then does a partial reload for the featured prop:

router.reload({
            only: ['featured'],
            data: {'featured' : id},
        onSuccess: () =>{
                showFeatured.value = true
            }
        });

This works great, but because it's a GET request I get a url like /feed?featured=59 which I want to hide.

Is there a way get the original 'GET' request to redirect to a 'POST' so that subsequent partial reloads don't change the url? Or is there a better way to achieve hiding the url?

Thanks for any thoughts!

p.s. I had wondered if this might work but it creates a loop:

        Route::post('/feed', [PostController::class, 'index'])->name('feed.post');
        Route::get('/feed', function () {
            return redirect()->route('feed.post');
        });
0 likes
6 replies
bwrigley's avatar

@jlrdw thanks for the reply and the link!

I should have explained a little more about the problem:

My Feed.vue Page shares a Layout component with every logged in Page.

This layout has a header which shows a dropdown of unread notifications.

I want the user to be able to click on a notification which will take the user to /feed endpoint but with the featured id as part of a post request.

I also want the user to be able to click on a Post whilst already on the /feed endpoint but in this case only do a partial reload of featured.

I've ended up using an ajax request if the user clicks a Post on the '/feed' page and doing a full page reload if the user clicks a post notification from the layout component.

This feels clumsy and more expensive than I'd like, but it works for now :)

jlrdw's avatar

In that video he doesn't cover placing a fetched partial in an object (similar to an iframe). He does cover the usage of Vue as well.

In business apps I place "lookup tables" instead of dropdowns in objects for an easy way to choose for example which carrier is hauling this load. Making the first td clickable.

The beauty of placing in an object is you still can have a search, pagination, etc.

It would be worth you going through the learning curve to do this at least once.

Also with this technique you have parent child back and forth communication as needed.

As example if I need to place something from child to parent such as a field I can easily:

window.parent.document.getElementById('mp').innerHTML = document.getElementById('mpage').value;

https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Other_embedding_technologies

But html can be used as well.

Edit

An older image, app was in work at the time. The table is in an object:

Alt image

Sorry another edit

Can I redirect a GET request to a POST request

Don't redirect, just do a post. But for things like loading a partial a get would work better I think. Later I may try using a post to see how it works out. But a get works.

bwrigley's avatar

@jlrdw Thanks again!

I did watch the video, and I think I have something similar to what he was suggesting albeit in a Vue setup, (which I know he was showing a Vue example to demonstrate how it's better not using Vue :) )

I see the logic of what you are saying about running inside an object, it makes good sense and I'm going to look at that more as I hadn't considered it! Thank you.

So I'm probably being dumb but I'm not sure it solves the problem I have or I haven't explained the problem I'm trying to solve very clearly.

Imagine the user initially hits an endpoint with a GET request to /. The Page loads but the table (as in your example) is empty as we don't yet know which data the user wishes to see.

As the user interacts with other elements on the page (or within the object itself), we can run ajax requests to grab data from the backend and reload the object as a partial as you suggest. All good.

Now in addition I want the user to be able to visit this page from a completely different page , but with parameters that define which data to show in the table on first load. So as a GET request this will now look something like /?show-table=54.

I don't want to show the query string, so I want to pass this data as a POST request which means I now need to support both GET and POST requests to the same endpoint calling the same controller method.

I can't find a way to make that work with my laravel routes e.g. this doesn't work:

        Route::post('/feed', [PostController::class, 'index'])->name('feed.post');
        Route::get('/feed', [PostController::class, 'index'])->name('feed');

Forgive me if I'm being dumb and misunderstood your reply! thanks again for your time.

jlrdw's avatar

@bwrigley I would create a logical path to get to your endpoint but still just have one way of doing it not two, just my suggestion and opinion.

And of course maintain a good KISS principle.

https://en.wikipedia.org/wiki/KISS_principle

Edit:

I am getting more images prepared, just a test data database.

Edit with example, just test data not styled good:

Alt image

Alt image

Alt image

Alt image

The modal or div in object can have a search, then the search results shown, then pick the one and parent form is filled in. Just example of object usage with a modal in this case.

For a lot of results, it's paginated:

Alt image

You should be able to adapt an object technique with a post or get depending on how you handle the request.

Again just test data here, so some crazy names.

Many times a first search is a post, then results are get request. But the router has the any method to handle that.

1 like
bwrigley's avatar

@jlrdw so sorry that I missed your reply!

Thank you for taking so much time to send me all this information. I'll look through properly.

Please or to participate in this conversation.