A
A
Alexander Lysenko2018-08-03 18:33:47
Laravel
Alexander Lysenko, 2018-08-03 18:33:47

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

1 answer(s)
A
Anton Anton, 2018-08-03
@Fragster

remove where, create a tree programmatically from the entire table.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question