Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search by descendants but get ancestors #561

Open
pls-kick-me opened this issue Jun 21, 2022 · 1 comment
Open

Search by descendants but get ancestors #561

pls-kick-me opened this issue Jun 21, 2022 · 1 comment

Comments

@pls-kick-me
Copy link

pls-kick-me commented Jun 21, 2022

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.

@YeftaAW
Copy link

YeftaAW commented Dec 21, 2023

Same issue here. Does anyone has any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants