Return to homepage



on episode 8 , there are some syntax changes since laravel 7 . also reading paul's suggestion following is the code , a quick tip you if you made changes in the boot method, tinker will not catch it up, i just spent half hr figuring what's wrong, just close and rerun the tinker and it should work.

1protected static function booted()
3 static::created(function ($comment) {
4 $base_id = $comment->id;
5 if ($parent = $comment->parent) {
6 $base_id = $parent->base_id;
7 }
9 $comment->base_id = $base_id;
10 $comment->save();
11 });
  • 0

if anyone trying to install sass in 2021 and getting error in vue 2.* run following cmd

npm install -D sass-loader@10.0.5 node-sass

  • 1

Test reply

  • 0

I like your solution, very clean and simple. One minor thing. in video 8 "Pagination with multiple nest levels" in the model boot method where you are setting the base_id to the top level comment ID I don't think it needs to be recursive. You can remove the "while" and simply get the base_id from the immediate parent of the comment. All comments in chain share the same base_id so the first parent will always have the same base_id as the new comment. If comment is top level (doesn't have a parent_id) then base_id = id.

Another interesting option is using recursive queries in the database with the "WITH RECURSIVE" command. I think it's now supported in all the latest open source databases, but is not compatible with older versions. Makes Laravel side a bit more complex but might be more flexible.

  • 6

Excellent. I had been struggling with pagination after building comment system based on your older 'Recursive comment nesting in Laravel'. Using base_id might solve query problems I was having, as I wanted infinite nesting for purposes of replies, but only displayed to two levels. I'm also using a 'load more' to expand level two as needed while still maintaining pagination on level 1. If I can now combine this with new stuff in Liker 2 course I'll have perfect timeline comments system :)

  • 1