© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
4 replies
Prodex

How can I avoid N+1 problem in custom views?

As described in the docs I use a custom view for a table column and I'm using $getRecord() to access the eloquent model.

This however makes an N+1 problem, because for every record displayed in the table the $getRecord() method retrieves the data from the database again.

How can I avoid this? Thank you!
Solution
Hi, this should help you:

        return $table
            ->modifyQueryUsing(function ($query) {
                return $query->with('relationship');
            })
        return $table
            ->modifyQueryUsing(function ($query) {
                return $query->with('relationship');
            })
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

How to avoid N+1 problem using eager laoding
FilamentFFilament / ❓┊help
2y ago
Badge N + 1 problem
FilamentFFilament / ❓┊help
2y ago
Colors in custom views
FilamentFFilament / ❓┊help
3mo ago
Custom Views
FilamentFFilament / ❓┊help
3y ago