A
A
Alexander Lysenko2018-07-20 12:45:27
Laravel
Alexander Lysenko, 2018-07-20 12:45:27

How do I redistribute child elements if the parent is deleted?

Hello. There is a table for example category with fields id | name | parent_id
5b51af1e1be28003302744.png
For example, there is such data in the table
Here is a link to json https://jsoneditoronline.org/?id=575f6dafdca44bbf9...
Or an array below

spoiler
stdClass Object
(
    [1] => stdClass Object
        (
            [name] => q
            [children] => stdClass Object
                (
                    [3] => stdClass Object
                        (
                            [name] => e
                            [parent_id] => 1
                            [children] => stdClass Object
                                (
                                    [4] => stdClass Object
                                        (
                                            [name] => r
                                            [parent_id] => 3
                                        )

                                    [5] => stdClass Object
                                        (
                                            [name] => r
                                            [parent_id] => 3
                                        )

                                )

                        )

                    [6] => stdClass Object
                        (
                            [name] => y
                            [parent_id] => 1
                            [children] => stdClass Object
                                (
                                    [7] => stdClass Object
                                        (
                                            [name] => u
                                            [parent_id] => 6
                                        )

                                )

                        )

                )

        )

)

So that's the QUESTION
For example, I'm deleting an element with id = 3 that has children id = 4,5
How can I make these child elements distributed among other elements? Those. so that they do not have parent_id = NULL (Only 7 elements are taken here, but there will be more than 20,000)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
JhaoDa, 2018-07-20
@LysenkoSasha

Subscribe to event deleting/ deletedmodels and distribute child elements to other elements.

I
Iris, 2018-07-21
@IrisPanabaker

You can also use JSON Editor to parse JSON data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question