2017-08-13 81 views
0

我正在开发一个项目laravel 5.2。但现在我有一个问题,在我的数据库中,有两个表userscommentsusers表包含id, email, username, password, created_at, updated_at列。 comments表格包含id, user_id, content, created_at, updated_at, deleted_at。现在在我的代码中,我有一个array,其中包含一些注释ID。我想获得users谁拥有这些意见。所以这里是我的代码:Laravel 5.2 where列表不明确

$commentIds = [ 
    .... 
    ... 
    ... 
]; 

$users = User::whereHas('comments',function($query)use($commentIds){ 

    $query->whereIn('id',$commentIds); 

}); 

但我得到异常说,列ID是不明确的。

+0

我们展示users'和'comments''之间的关系。 –

回答

0
$users = User::whereHas('comments',function($query)use($commentIds){ 
    $query->whereIn('comments.id',$commentIds); 
}); 

将工作