我有一个像这样的树枝代码:
{% for row in faq_categories|batch(2, 'No item') %}
<div class="row">
{% for faq_category in row %}
<div class="col-lg-6">
<h3>{{ faq_category.name }}</h3>
<p>{{ faq_category.description }}</p>
{% set faqs = getFaqs( faq_category.id ) %}
<div class="accordion toggle fancy radius clean">
{% for faq in faqs %}
<div class="ac-item">
<h5 class="ac-title"><i class="fa fa-question-circle"></i>{{ faq.question}}?</h5>
<div style="" class="ac-content">{{ faq.answer }}</div>
</div>
{% endfor %}
</div>
</div>
{% endfor %}
一切都很正常,但是当我只有1条faq_categories记录时,它会给我一个这样的错误:
Message: 'Argument 1 passed to App\Models\Faq::byCategory() must be of the type int, null given, called in D:\laragon\www\compro\Core\View.php on line 86'
它是由这行代码引起的:
{% set faqs = getFaqs( faq_category.id ) %}
似乎faq_category.id 变为 null。我不知道是什么让这种情况发生,是因为批处理过滤器吗?还是我在这里做了一些事情?
明月笑刀无情