-2
I am having trouble passing a Javascript variable into a Laravel route. To do so, I am using an AJAX request. The code I’m using is just below:
            $.ajax({
                url: 'rota/emails/'+p.id,
                type: "GET",
                data : {"_token":"{{ csrf_token() }}"},
                dataType: "json",
                success:function(data) {
                  if(data){ 
                    $.each(data, function(key, value){
                      $('#received-emails').append('<div class="text-center">' + value.email+ '</div><a class="btn btn-danger" href="{{route("rota.delete", '+value.id+')}}"><span class="fa fa-user-times"></span></a>'); //o problema esta nesta linha
                    });
                  }
                }
              });
In the use of id #received-emails, i add the Divs with the respective HTML shown above. O value.email works properly, ja the value.id no. in my controller, the id is received as +value.id+ and not as their id which is being acquired by AJAX. 
At first I’m trying to create a simple button that when clicking on it, is redirected to a route from Laravel where this is the delete feature. As the example below:
<a href="{{route('rota.delete', id)}}"></a>
I ended up building something like this inside the append:
'<a class="btn btn-danger" href="{{route("rota.delete", '+value.id+')}}"><span class="fa fa-user-times"></span></a>'
What can be the solution to this problem?
Switch to
href="{{route("rota.delete", value.id)}}"– Douglas Teles
an error such as: Use of Undefined Constant value - assumed 'value' (this will throw an Error in a Future version of PHP)
– Arthur Abitante