This is my data structure:
Models:
-
Topic
hasMany
Article
-
Article
belongsTo
Topic
andhasMany
Comment
-
Comment
belongsTo
Article
- Additionally,
Topic
hasManyThrough
Comment
(viaArticle
)
DB tables:
-
topics
: intid
, stringlabel
-
articles
: intid
, stringcontent
, inttopic_id
(foreign key) -
comments
: intid
, stringcontent
, booleanapproved
, intarticle_id
(foreign key)
Now, I want to iterate over all topics
that have articles
with approved
comments
.
@FOREACH ($topics->where(...) as $topic)
<div>
{{ $topic->label }} has {{ $topic->articles->count() }} articles with approved comments.
</div>
...
@ENDFOREACH
Unfortunately, I can't figure out how to define the where
-clause. Or should it be a when
-clause? Here is a list of the methods available for Laravel Collections.
Any help is greatly appreciated!