I want to concatenate javascript variable within blade {{ curly braces }}
as following:
Currently:
ajax: "{{ route(api.colors) }},"
What I want:
var page='colors';
...
ajax: "{{ route(api."+page+") }},"
Is it possible?
I want to concatenate javascript variable within blade {{ curly braces }}
as following:
Currently:
ajax: "{{ route(api.colors) }},"
What I want:
var page='colors';
...
ajax: "{{ route(api."+page+") }},"
Is it possible?
You cannot do this directly because the curly brackets are rendered on the server and javascript runs on the client side. You could put a placeholder in you route and then replace this part in your javascript code. Like so:
// Imagine the `api.page` route value is `/controller/{page}`:
ajax: "{{ route(api.page) }}".replace("{page}", page);
{items}
? –
Tarver You can try this code, it worked for me.
var id = $('#user_id').val();
console.log(id);
ajax: "{{ URL::to('/meme') }}/poster/"+id+"",
You can use the ziggy library.
It has a helper function route(route_name)
that you can easily use for this purpose.
© 2022 - 2024 — McMap. All rights reserved.