Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

samalapsy's avatar

Pass Value to Laravel Named Routing from javascript

I want to add a value to my named routing from javascript

This is my route 

{{ route('admin.edit_school', ['slug' => $variable_here]) }}

This is what I tried but it's not working

var slug = $(this).data('row-abbreviation');
var url = "{{ route('admin.edit_school', ['slug' => '"+slug "']) }}";
window.location.href=url;

Please how can I achieve this..

0 likes
7 replies
alex-greaves's avatar
Level 1

var url = '{{ route("admin.edit_school", ":slug") }}';

url = url.replace(':slug', slug);

window.location.href=url;

16 likes
Archu's avatar

var slug = $(this).data('row-abbreviation');

var base = '{!! route('admin.edit_school') !!}';

var url = base+'?slug='+slug ;

window.location.href=url;

1 like
sk_fahad's avatar

In my opinion the simplest way is by passing the empty string in place of route paramtere then concatenating javascript variable with blade string as follows.

var url = "{{route('admin.stocks.edit', '')}}"+"/"+stock.id;

3 likes

Please or to participate in this conversation.