How to escape a javascript variable to the Laravel Slide?

Asked

Viewed 906 times

0

Hello, I have this javascript function that receives a parameter:

function teste(id){
  document.getElementById("campo1").innerHTML = id;
  document.getElementById("campo2").innerHTML = {{app\User::find("id")->titulo}}
}

How do I get the User::find() function to take the 'id' variable that is from javascript, is there any way to do this?

1 answer

1


The function is not possible teste(id) runs at runtime on the front-end, {{app\User::find("id")->titulo}} is Blade which in turn is part of Laravel which is a PHP framework and runs in the back end is processed and delivered the front end already ready.

So you can’t do this and nor is it a logical thing to do, it is best to change the strategy, but it will depend on what User::find("id")->titulo has to do and what the teste() really does. The way it is hard to give an alternative.

  • 1

    Thanks William, the issue of the Lade run in the back-end cleared my doubt.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.