Laravel Eloquent - “whereNotIn”使用子查询?

时间:2015-09-23 11:13:40

标签: php laravel eloquent

我正在努力弄清楚如何将这个SQL用于雄辩的方法。

SELECT * FROM artists WHERE artists.id NOT IN
(SELECT artist_id FROM artist_issues WHERE issue = 'update_images')

我看到“whereNotIn”方法接受一个列,然后一个数组作为第二个参数,因此无法传递子查询。

我有什么想法可以做到这一点?

感谢。

1 个答案:

答案 0 :(得分:0)

假设您设置了正确的关系,它应该是这样的:

$artists = Artist::whereHas('artist_issues', function(q) {
   $q->where('issue', '<>', 'update_images');
});

我猜你的Artist模型中有这样的东西:

public function artist_issues()
{
    return $this->belongsTo('App\ArtistIssue');
}