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

Abzor's avatar
Level 5

Send data from a Vue page to a Laravel route with Inertia?

I have a Vue page where I want to send data to the backend at some point to store it in the database.

I have tried the following in a function: Inertia.post('/some-endpoint', { data: 'some data' });

Only this causes the page to reload itself. And this only happens in the production build via Vite and not locally 🤔

If I understood correctly, the advantage of Inertia is that you don't have to create an api and that you can directly call the Laravel web routes.

How can data be sent from a Vue page to a Laravel route (with Inertia?) ?

0 likes
5 replies
vincent15000's avatar

I already had a different behavior between the local one and the production one.

I send my data to the backend via a slightly different way.

import { useForm } from '@inertiajs/inertia-vue3'
...
const form = useForm({
  name: null,
})
...
function submit() {
  if (props.roomId) {
    form.put('/rooms/'+props.roomId, {
      onSuccess: () => {
        close()
      },
      onError: (error) => {
        errors.value = error
      }
    })
  } else {
    form.post('/rooms', {
      onSuccess: () => {
        close()
      },
      onError: (error) => {
        errors.value = error
      }
    })
  }
}
Abzor's avatar
Abzor
OP
Best Answer
Level 5

In the Inertia documentation I have found a working solution:

import { router } from '@inertiajs/vue3'

router.post(url, data, options)
2 likes
dcranmer's avatar

Do an axios request (post, patch, etc., depending on what you need to do) in a Vue method. No need to do anything specifically with Inertia for this.

Please or to participate in this conversation.