Answer the question
In order to leave comments, you need to log in
How to use JavaScript inside PHP in Laravel?
The task is the following: count the number of elements in JS and display the number with the correct declension (eg "1 order / 2 orders / 5 orders") using Laravel lang files.
At first, I used a simple JS function for declensions, and simply stored three different declensions in lang files. After that, I was told that it is wrong to do this and there is a standard function in Laravel that does this trans_choice. But there was a problem when integrating the JS variable into the PHP code of this function. It turned out something like this (in a simplified form):
// определяем количество карточек в колонке
var cardsLength = 3;
// и записываем
countText = cardsLength+' {{ trans_choice("sales_order.order_declension", '+cardsLength+', [], "ru") }}';
Answer the question
In order to leave comments, you need to log in
At the time of rendering the page, Js has not yet been worked out.
Still, I advise you a way to solve this in a standard way.
PS Write in more detail what you are doing and what you want to achieve as a result - and I will try to tell you how to do it more elegantly using PHP + Js environments
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question