thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.78k stars 2.67k forks source link

Can you please solve the N+1 Query problem? #5567

Open anyouzy opened 2 years ago

anyouzy commented 2 years ago

Laravel version

9.2

PHP version

8.0.3

Voyager version

1.5

Description of problem

I have a merchants table containing a category_id field. And I create the belongsTo relationship.

image

Now when I visit the /merchant, I found that there is an N+1 query problem when fetching the category info of a merchant:

image

I created my own controller that extends \TCG\Voyager\Http\Controllers\VoyagerBaseController, and try to lazy load the category data. However, it doesn't work. The N+1 query problem still exists.

image

Proposed solution

How can I solve the N+1 query problem?

Alternatives considered

No response

Additional context

No response

Sophist-UK commented 2 years ago

@anyouzy You probably need to work out how this needs to be fixed and submit a PR.