Skip to content
Advertisement

Nested comment system runs too many queries ( laravel & livewire )

I’ve built a nested comment system and it works fine, but I have a problem. when I want to show the comments, it runs too many queries. for example if I have 10 comments and two replies each, laravel debugger shows 40+ queries, and I want to reduce them, here is my code :

Query

JavaScript

Relationship in Post.php Model

JavaScript

Comments Relationships

JavaScript

Blade File

JavaScript

Advertisement

Answer

You can use dot seperator to get the nested relationship

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement