0

I'm trying to submit a form which is in Vue and my route is

http://cricketstats.test/en/dashboard/players/z2d4ca09a7/india/941/runs

Here 941 is the player id. I want this id also to be passed to the laravel controller along with the remaining form data.

Is there have anyway to fetch this id from the url in vue, and pass it to the laravel controller?

1
  • 1
    Have you tried using axios/ajax? Commented Apr 5, 2022 at 2:58

1 Answer 1

1

The simple code below will extract what you need.

After this, all you need to do is make an ajax/axios request going to the controller.

var url = 'http://cricketstats.test/en/dashboard/players/z2d4ca09a7/india/941/runs';
var url_split = url.split("/");
var my_id_location = url_split.length - 2;
var my_id = url_split[my_id_location];
console.log(my_id );

Here's an idea about how you can send the data to the controller using ajax:

$.ajax({
  url: "/your/url",
  method: 'POST',
  data: {id:my_id, _token:token},
  success: function(data) {
    //if success
  }
});
Sign up to request clarification or add additional context in comments.

2 Comments

okay, here i'm having small question, when passing this value to the controller how can I do it, because it's not a form data, hence i can't use formData.append, right?
i have updated the answer and used ajax instead of axios for simplicity.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.