Echo vuejs data inside php function
I currrently want to echo vuejs data inside a php function like so:
{{ auth()->user()->timesAddedBeer(@{{ beer.id }}) }}
But laravel gives me the following error:
syntax error, unexpected '{'
Can anybody tell me the right way to do this?
You can't add JS data to a php function.
Is that value stored in your database? If so, just query it in the controller and pass that data to the view...
If not, you can try using ajax to make the auth->user()->timesAddedBeer() call.
var beerId = {{ beer.id }};
$.ajax({
type: 'GET',
url:'/get/beer/id/route',
data: beerId,
success: function(data) {
//set value in the dom
}
});
PHP = Serverside, JS = client side.
It's a value from Algolia. Anywhere else I am able to echo that value on the page like so:
@{{ beer.id }}
I don't want to add an ajax request when it can be done cleanly. I will try to look for another option.
Good luck. You can't mix Mustache binding and php. Another opinion is session or local and call it up via JavaScript.
Please or to participate in this conversation.