vendredi 24 juin 2016

Fetch children of nested tree first

I have a table (let's call it entries) that looks like this:

id  parent_id
1   0
2   1
3   2
4   1
5   4
6   5
7   4
8   1

As a tree, this looks something like this (where the number is the id):

- 1
    - 2
        - 3
    - 4
        - 5
            - 6
        - 7
    - 8

I want to get an array of these IDs starting from the inner most child and working its way up.

The output should be:

[3, 2, 6, 5, 7, 4, 8]

I'm using Laravel 5.2.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/28TKxdL
via IFTTT

Aucun commentaire:

Enregistrer un commentaire