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');
            })
Was this page helpful?