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

vannian's avatar

How to pass parameter to controller from vue

I want to pass parameter to the controller from vue in a navigation.vue.

< Link class="w-full" :href="route('transaction.index')" >2023< / Link >

do not know how to pass, If I put like this it gives an error:

 < Link class="w-full" :href="route('transaction.index', ['year' => 2023])" >2023< /Link >
0 likes
4 replies
Tray2's avatar

There are two ways of passing data to the controller vi a link.

Option 1, is to use the query string mysite.com/something?value1=somevalue&value2=somevalue Option 2, is with the url itself `mysite.com/something/somevalue/somevalue

If you handle the request with javascript then you can pass a json body to the controller.

https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

1 like
vannian's avatar

so in this case if I want to pass as query param, how can I pass?

1 like
martinbean's avatar

@vannian Why not just pass the built URL to your JavaScript?

You can’t call PHP functions in JavaScript like you’re trying to. route is a PHP function. The PHP process has been and gone before a single line of JavaScript is executed in your browser.

1 like

Please or to participate in this conversation.