这是我的数据结构:
楷模:
Topic
hasMany
Article
Article
belongsTo
Topic
和hasMany
Comment
Comment
belongsTo
Article
数据库表:
Topic
:int hasManyThrough
,string Comment
Article
:int topics
,string id
,int label
(foreign key)articles
:int id
,string content
,boolean topic_id
,int comments
(foreign key)现在,我想迭代所有与id
content
有approved
的article_id
。
topics
不幸的是,我无法弄清楚如何定义articles
子句。或者它应该是approved
条款? comments
是Laravel Collections可用方法的列表。
任何帮助是极大的赞赏!
@FOREACH ($topics->where(...) as $topic)
<div>
{{ $topic->label }} has {{ $topic->articles->count() }} articles with approved comments.
</div>
...
@ENDFOREACH
或者你可以用类似的方式使用你的where
关系,但我没有一个例子可以尝试一下。