Fetch an ID from a URL and pass it to the laravel controller in VueJS

Solution:

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
  }
});