我正在使用laravel 5.1。我有两个型号
articles
authors
我想找到已发表或有两位以上作者的文章。在雄辩中最简单的方法是什么?
$pub_articles = Articles::where('published',1)->get(); //get articles that are published
我猜是
$articles = Articles::where('published',1)
->orWhere(Articles->authors::count(),'>',2);
在SQL中它可能以这种方式完成
select a.id, a.published from articles a inner join authors au on a.id = au.article_id where a.published = 1 group by a.id, a.published having count(*) > 2
答案 0 :(得分:0)
您是否尝试过has
方法?
Articles::has('authors', '>', 1)->where('published',1)->get();