Answer the question
In order to leave comments, you need to log in
How to count the number of positive comments?
Hello! There is a list of testimonials that may or may not contain positive comments. Question: How to correctly display the number of reviews that contain positive comments?
{% for item in ReviewComponent.reviews.items %}
{% if item.attributes.page_casino == record.slug %}
{% component 'ReviewComponent' %}
{{ dump(item.positive)}} - положительный комментарий
{% endif %}
{% endfor %}
Answer the question
In order to leave comments, you need to log in
It is advisable to move the logic of positive comments to the controller / service, and not to do it in the view.
I would do it something like this:
public function getPositive(array $reviews): integer
{
return collect($reviews)->filter(function ($el) {
retrun $el->rating > 2; // Здесь логика фильтрации.
})->count();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question