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

ezheng's avatar

Laravel Inertia Redirect back

Hi, Have anyone success using redirect()->back()->withdata in inertia?

I am trying save my category from products.index.vue.

Here is my code : CategoryController

public function create(Request $request)
    {
        // save to database
        $category = $this->store($request);

        // Return a JSON response indicating success
        return redirect()->back()->with([
            'category' => $category,
        ]);
    }

here in my product.vue

const handleCreateCategory = (data) => {
                router.post(route('category.create'),
                    {
                        //data
                        name: data,
                    }, {
                        onSuccess: (res) => {
                            console.log(res);
                        }
                    }
                );
            }

When i redirect back, it doesnt with 'category' props. How to solve this?

0 likes
5 replies
MohamedTammam's avatar

redirect()->back()->with() store this information in the session. Inertia front-end doesn't know about your back-end session.

And more importantly that isn't a good way to send back updated category. What do you want to do here exactly? what's the purpose of returning that category back?

ezheng's avatar

HI, thanks for your reply.

Here is my real condition. I have using Vue3Multiselect, inside here i use :tag to Create New Category ( If Data Not Exist )

Here is my multiselect :

<Multiselect 
                                                            id="selectCategory"
                                                            v-model="category_id"
                                                            :options="categories" 
                                                            :searchable="true" 
                                                            :label="'name'"
                                                            :track-by="'id'"
                                                            :allow-empty="false"
                                                            :taggable="true"
                                                            @tag="handleCreateCategory"
                                                            placeholder="Example: Laptop">
                                                        </Multiselect>

so when it run handleCreateCategory, it will run router.post like my previous code.

After that, i need Multiselect is selected that data. But the multiselect doest view the newest selected category that i create.

Do you have any clue if i want create like that process?

MohamedTammam's avatar

@ezheng You need to just redirect back and for that route (the one that has the multi-select) you load all categories again.

ezheng's avatar

@MohamedTammam can you please give me an example in rredirect back? Because i already try this :

 return redirect()->back()->with([
            'category' => $category,
        ]);

But it doesnt load 'category' with it when it redirect back

MohamedTammam's avatar

@ezheng Just do

return redirect()->back();

And then in this page load the categories.

Please show the code for that page that shows the categories multi-select.

Please or to participate in this conversation.