Good day. Am trying to query my database to get the child of a child of a child. Every user has 2 children. Am using query builder. The requirements is not to use eloquent and eloquent relationships. But am struggling with it.
$firstchild= DB::table('users') - >where('parent_id', Auth::user() ->id) -> get() ;
$secondchild1 = DB::table('users') - >where('parent_id', $firstchild[0]->parent_id) -> get() ;
$secondchild2 = DB::table('users') - >where('parent_id', $firstchild[1]parent_id) -> get() ;
return view('home' ['firstchild' => $firstchild, 'secondchild1 ' => $secondchild1, 'secondchild2 ' => $secondchild2 , ])
It returns undefined offset 0 if the user child has no child. How do i do it if i want to get without any errors.
If I want to get the children of those children the query results gave, how will I do so?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire