Answer the question
In order to leave comments, you need to log in
How to get all HasMany nestings?
There is a table
id parent_id
How to get all nestings and then transfer to the front?
There is a
categories model
in it a method
public function children()
{
return $this->hasMany('App\Category', 'parent_id', 'id');
}
In the controller
$data = $comment->with('children')->where('parent_id', null)->get();
But only one level of nesting comes. How to make a complete query to get all child elements?
I understand that if you do this through foreach in the view and check children there, then everything will be fine, but I need to pass it through json
Answer the question
In order to leave comments, you need to log in
remove where, create a tree programmatically from the entire table.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question