Answer the question
In order to leave comments, you need to log in
How to get (number of records with condition) from linking model?
There are the following tables: and models Article
, Tag
and Comment
.
When you click on a tag, you need to get a list of articles with a specific tag .
The fact is that the table articles
does not know about tags and data can only be obtained from a table article_tag
that does not have a model.
Temporarily solved the issue without models like this:
$countArticles = DB::select( 'SELECT COUNT(*) AS c FROM article_tag WHERE tag_id = ?;', [$tagID] )[0]->c;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question