Laravel 5.2 whereHas column is ambiguous

Viewed 1990

I am developing a project with laravel 5.2 . But now I have a problem, In my databases, there are two tables users and comments. users table contains id, email, username, password, created_at, updated_atcolumns. comments table contains id, user_id, content, created_at, updated_at, deleted_at. Now in my code, I have an array which contains some comment id. I want to get users who owns these comments. So here is my code:

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

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

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

});

But I get exception said that column id is ambiguous.

1 Answers
Related