Skip to content
Advertisement

Redirect route with data in Laravel Vue Inertia stack

In my controller i have

JavaScript

and i used ‘msg’ in my props

JavaScript

But for {{msg}} gives undefined and not any message.

Advertisement

Answer

You’re passing msg as a param to your route, not as a param to your Inertia::render call. And since you’re redirecting, you probably want to flash the message to the session and handle it on the HandleInertiaRequests middleware. Look into the example in the documentation.

So, first you redirect to rooms.index flashing the message:

JavaScript

Then, Inertia requests the rooms.index route as a XHR request and before it hits your Controller, it passes through the HandleInertiaRequests middleware.

JavaScript

Now you can access it in your component via:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement