I am trying to send ID of record to resource controller for edit through AJAX request in Laravel. My code is like below.
function editdetails(id) {
$.ajax({
type:'GET',
url:"{{ route('users.edit', id ) }}",
success:function(data){
console.log(data);
}
});
}
But I am getting error like below.
Use of undefined constant id - assumed 'id' (this will throw an Error in a future version of PHP)
2
Answers
Since you are using javascript here, you can’t use blade syntax. In order to achieve this, you either have to use URL as a string that you defined in your routes file:
or you can save your route in some hidden element on you page and use it in js, for example:
You can use like this:
As in your code:
Replace this: