Home > Mobile >  How to pass a value to laravel controller which is not in a form input in VueJS
How to pass a value to laravel controller which is not in a form input in VueJS

Time:04-05

In my VueJS application, I have a form to submit some data

Admin can fill the same data for aother system user as well.

When an admin fill these data for a different user, I need to store that user's user id in the DB.

I'm fetching that user id from the URL.

But I'm struggling to pass that user's user id with the rest of the form data.

How can I pass that user id with the rest of the data to my laravel

This is how I fetch the user id and store it

var url = window.location.href;
var url_split = url.split("/");
var my_id_location = url_split.length - 2;
var my_id = url_split[my_id_location];

This is how I pass my form data

            const formData = new FormData()
            formData.append('match_id', this.matchId)
            formData.append('ground', this.ground)
            formData.append('played_at', moment(this.dateOfStart).format('DD-MM-YYYY'))
            formData.append('ended_at', moment(this.endedDate).format('DD-MM-YYYY'))

Since my_id is not a form data, how can I pass that value ?

CodePudding user response:

It's same what you did with form data. Add like this

formData.append('my_id', my_id)
  • Related