ฉันมีรหัสทวิกเช่นนี้:
{% 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 %}
ทุกอย่างเป็นปกติ แต่เมื่อฉันมีบันทึก faq_categories เพียง 1 รายการ มันทำให้ฉันมีข้อผิดพลาดดังนี้:
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'
มันเกิดจากรหัสบรรทัดนี้:
{% ตั้งคำถามที่พบบ่อย = getFaqs( faq_category.id ) %}
ดูเหมือนว่า faq_category.id จะกลายเป็นโมฆะ ฉันไม่รู้ว่าอะไรทำให้เกิดสิ่งนี้ เป็นเพราะตัวกรองแบตช์ใช่ไหม หรือฉันได้ทำอะไรบางอย่างที่นี่?