I am trying to open a Laravel route using javascript when user click on anchor tag
but the problem happened when I send parameters with route
I write the javascript code as following
$("#accept_order").click(function() {
var url = "{{ route('update_order',["+order_id+",1]) }}";
location.href = url;
});
but when executing the code the final route looks like
http://127.0.0.1:8000/update_order/+order_id+/1
I have tried the accepted answer on the following question Laravel 4, Pass a variable to route in javascript but I got a runtime error when executing it.
2
Answers
I don’t think that is a good idea anyway.
in this situation i think it is better to pass your variable through url
and then get the value by $_GET[‘key’] for example you can redirect to current page and append the value to url
You need to concatenate the string on the javascript side, not within blade tags. You cannot use the route helper for this as Laravel will complain that you have not provided the required parameter for the route.
So supposing the
'update_order'
route is actually/update_order
then;