0

laravel route helper parameter with JavaScript There is a problem.

<script>
    let url = "<a href='{{ route('admin.user.update', ["+ row.idx +"]) }}' class='link-success'>"
</script>

result https://example.com/user/update/+%20row.idx%20+

Result value I want https://example.com/user/update/1023223

6
  • Is that inside a blade view? Then use blade syntax to get the result. What does left url do? Commented Sep 1, 2021 at 6:15
  • stackoverflow.com/a/56430916/7964905 check this answer Commented Sep 1, 2021 at 6:26
  • 1
    You try to mix php (blade) and javascript. The php is server side, javascript client side. you can output the url, and change it with javascript, but you can't expect blade to use js vars. Commented Sep 1, 2021 at 6:32
  • Please share your route Commented Sep 1, 2021 at 6:34
  • @brombeer Modified to "let". inside the blade template (blade.php) Commented Sep 1, 2021 at 7:06

1 Answer 1

0
<script type="text/javascript">
let url = "<a href='{{ route("admin.user.update/'+ row.idx +'")]) }}' class='link-success'></a>"</script>
Sign up to request clarification or add additional context in comments.

4 Comments

Still uses javascript and blade mixed, this can not work. How does this answer get accepted? And the route syntax is wrong. It's a named route, so the / does not belong there. This will throw a "route not defined" error
<script type="text/javascript"> let url = '<a href="{{ route("admin.user.update/'+ row.idx +'") }}" class="link-success"></a>'</script>
No, you can not use + row.idx + in {{ route() }} and the route name is admin.user.update. This might work depending on the route file: href="{{ route("admin.user.update") }}/'+ row.idx +'"
There is an edit link below your answer post. Please use that to update your post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.