Answer the question
In order to leave comments, you need to log in
How to pass variables from laravel to js?
Hello. I'm still tormented by the question of how to most correctly pass variables from laravel to js. Store in hayden inputs and receive in js or data attributes or through <script>var id = '{{$post->id}}';</script>
Or is it possible somehow? What is the most convenient and most correct way to do this? For example, you need to pass the post ID .. I want to come to one rule, otherwise I do it somewhere, somewhere like that, in the end ...
Answer the question
In order to leave comments, you need to log in
Everything is individual here, personally I use the data attribute. The code is less heaped up and access to data for writing and reading is more convenient.
If you use jquery, then everything boils down to this:
$('body').data('name_data'); - for reading;
.data('name_data','insert') per entry
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question