0

I 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?

5
  • You could use plain <?php tags instead of {{. Commented Oct 6, 2015 at 15:38
  • That does not work since the outer braces are from the blade templating of laravel and the inner @{{ }} braces are from vuejs itself so they are not php and are needed. Commented Oct 6, 2015 at 15:42
  • Maybe triple {{{ $data }}} to echo? Commented Oct 6, 2015 at 19:20
  • So what's stoping you from doing something like this? <?php auth->user->()->timesAddedBeer(?> @{{ beer.id}} <?php ) ?> Commented Oct 6, 2015 at 20:08
  • The vuejs data is loading a fraction slower than the page so the php function is trying to execute with the laravel values of the mustache binding instead of the translated value. Commented Oct 7, 2015 at 22:47

1 Answer 1

3

It's not possible because the server can't access the JS value at the time executing the php script.

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

2 Comments

Then what is a solution ?
EIther pass the data to the client through PHP or use AJAX from the client

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.