Parent&Child Last updated: 2022-11-20

Sometimes you need to extract a child subsection from a main section, so how do you do that?

We will put a simple example for you to define the parent section to prepare the child sections

We have a parent it called Version & and child it called section

 

belongsTo()->make('Version', 'version', Versions::class)->child('section'),
belongsTo()->make('Section', 'section',Sections::class)->fromParent('version', 'version_id'),

 

See we have set the method child  Let the Parent know that this is his Child

and See we have set the method fromParent  Let the Child know that this is his Parent

If we define the child, what is the key that fetches the children based on it version_id

 

version // ->child('section'),

section // ->fromParent('version', 'version_id'),

So the result is as follows

 

 After we chose the first version, it showed us a list of children 
We chose the Relationships child

That's it