I have a User
table and need to allow for users to have a parent user.
the table would have the fields:
id
parent_id
email
password
How would I define this self referencing relationship in Eloquent ORM?
I have a User
table and need to allow for users to have a parent user.
the table would have the fields:
id
parent_id
email
password
How would I define this self referencing relationship in Eloquent ORM?
I had some success like this, using your exact DB table.
User Model:
and then I could use it in my code like this:
Give that a try and let me know how you get on!
I had a chain of self referencing contracts (a contract can be continued by another contract) and also needed self referencing. Each contract has zero or one previous and also zero or one next contract.
My data table looked like the following:
To define the inverse of a relationship (previous contract) you have to inverse the related columns, that means setting * foreign key column on the model table * associated column on the parent table (which is the same table)
See http://laravel.com/docs/5.0/eloquent#one-to-one for further details.