A
A
Artem00712018-08-17 13:41:39
Laravel
Artem0071, 2018-08-17 13:41:39

How to do pagination of comments with a tree system?

The situation is as follows: Each
comment can have a "parent" The nesting
can be infinite it would be to find out the parents in the first query and then just look at the children . And how to do the same, but only when the nesting can be infinite? My shortcoming: As for me, you can make each comment an additional attribute "0-parent" and I think this would solve the problem . But the problem is that this would have to rewrite the entire table . Maybe there is some other solution?


Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin B., 2018-08-17
@Artem0071

Any package for working with nestedset will solve your problem, for example this one https://github.com/lazychaser/laravel-nestedset
Install the package, create a migration as described in the documentation, add a trait to the comment model, run a command in the console that will automatically recalculate everything.
Then you can select all parents page by page and upload internal comments to them . There are a whole bunch of methods in the documentation that will allow you to realize any desires. See try

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question