Get the only Posts which don't have replies

Posted 3 years ago by saqueib

I wanted to get all the Post which do not have any replies post by type a, here is Post Model & relation. Please help how can I do it in Eloquent

class Post extends Model
{
    public function replies()
    {
       return $this->hasMany(Post::class, 'parent_id');
    }
}

posts table schema.

id     |     title   |   body    |  parent_id   | type 
1      |    abcd...  |  xyz...   |  null        | a
2      |    abcd...  |  xyz...   |  1           | b
3      |    abcd...  |  xyz...   |  null        | a
4      |    abcd...  |  xyz...   |  1           | b
5      |    abcd...  |  xyz...   |  1           | b

Please sign in or create an account to participate in this conversation.