4

I'm using Vue.js and Laravel to render a simple table listing products. From there I want to link to a product detail page like this:

<a href="{{ route("product::details", ['product' => '???']) }}">@{{ product.id }}</a>

Since the table is generated on client side base on a data object, I'm looking for the most elegant way to implement that while not bypassing any laravel methods like route() that allows me to link to a named route.

Do I really have to manually merge the result of the route-method with the Vue variable in Javascript?

In my mind is something like:

<a href="{{ route("product::details", ['product' => ':product.id']) }}">@{{ product.id }}</a>

which I could probably parse/inject by Vue via data binding?

4
  • Similar to the following question, but I need to merge "backend parameters" into the link target: stackoverflow.com/questions/32560184/… Commented Mar 24, 2016 at 12:28
  • Are you using laravel or vue-router for your routing? I can't think of a way this would work off the top of my head, as both of them either require a path, or a named route + parameters Commented Mar 24, 2016 at 15:47
  • I'm using laravel for routing. Commented Mar 25, 2016 at 8:16
  • hmm, have you tried <a href="{{ route("product::details", ['product' => '@{{ product.id }}']) }}">@{{ product.id }}</a> ? Commented Mar 31, 2016 at 5:04

1 Answer 1

6

As Vue it's client side and laravel it's server side you can't accomplish that in that way.

But you can do something like this over the rendered route:

Create a vue method

goto_route: function (param1) {
     route = '{{ route("yournamedroute", ["yourparameter" => "?anytagtoreplace?"]) }}'
     location.href = route.replace('?anytagtoreplace?', param1)
}

Now in your action element

<div v-for="o in object">
     <a v-on:click="goto_route(o.id_key)">press</a>
</div> 

Basically you're replacing the... uhmm... let's name it "placehoder" in the rendered route with the required value.

hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

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.