Hi I am trying to build an app where there are parent elements which have children and each child has its own sub child. I am having a pivot table which consists of user_id, plan_id and child_id, Now I am trying to fetch the child. How can I fetch all the children in an array.:
I am trying following code:
$user = Auth::user();
$selectplan = 1;
$children = $user->relations()->wherePlanId($selectplan)->first()->pivot->child;
I am able to get only first child, but I have more rows to be fetched:
/**** Table Column ****
*
*
/--id----user_id----plan_id----child----created_at----updated_at
1 1 1 2 NULL NULL
1 1 2 3 NULL NULL
1 1 1 4 NULL NULL
1 2 1 7 NULL NULL
1 2 1 8 NULL NULL
1 2 3 10 NULL NULL
Please help me out. Thanks!