laravel-nestedset
laravel-nestedset copied to clipboard
Search by descendants but get ancestors
Hello community and thanks to creators for beautiful package! Suppose I have a tree:
- parent1 -- child1 -- child2 --- grandson1 --- grandson2
- parent2 and so on...
I need search children and grandsons (and next depth levels) but tree should be like above (in natural order).
After search:
Category::with('ancestors')
->when($request->title, function ($query) use ($request) {
$locale = app()->getLocale();
$title = $request->title;
$sql = "title::json->>'$locale' ilike '%$title%'";
$query->whereRaw($sql);
});
I get something like:
- grandson1 -- ancestors[ --- child1 ---- ancestors [ ----- parent1 ] ]
But I need normal tree. I must do reverse by hand or there is a way?
reversed() doesn't do the job, it is reverse in one depth but I need swap ancestors and descendants (the most depth level should be first) Thanx.
Same issue here. Does anyone has any ideas?