How to get all the people in table 1 without getting the people who have me as parent_id in table 2?

I’m writing this post because I have a problem with my relationships on Laravel.

Here is the structure I currently have:

1st table:
– id
– name
– …

2nd table :
– parent_id
– child_id

knowing that parent_id and child_id correspond to the same table. Here is the function that links them

public function relation()
{
    return $this->belongsToMany('AppPerson', 'person_relations', 'parent_id', 'child_id', 'id', 'id');
}

Currently I would like, for a search system, to get all the people in table 1 without getting the people who have me as parent_id in table 2.

Thanks,
Ben

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *