Epsilon47
Epsilon47

Reputation: 838

Vue inside of blade - syntax

How can I put Vue's variables into the Laravel's mustache brackets in following expression?

<a href="{{URL::route('frontend.article.show', ['slug' => '@{{article.slug}}', 'categoryId' =>'@{{ @article.id}}'])}}">"@{{article.title}}"></a>

This throws me an error like:

Parse error: syntax error, unexpected '}', expecting ',' or ')'

Upvotes: 0

Views: 441

Answers (1)

Chris
Chris

Reputation: 3486

The problem is you are trying to access Vue variables (client side) inside of a PHP statement (server side). One way to solve this issue is to create the links inside Vue's mounted() method. How you can do this as follows:

First create the tags as follows

<a id="@{{ article.id }}" href="">@{{ article.title }}</a> 

Then, you need to create the appropriate links inside Vue's mounted() method (or created())

let path = "{{ route('frontend.article.show', ['slug' => 1, 'categoryId' => 2]) }}";
let url = path.replace(1, article.slug).replace(2, article.id);

// manipulate the DOM from here or pass it through to your data.

This is one way to approach it.

Upvotes: 1

Related Questions