FilamentF
Filament2y ago
Vp

How to eager load relationship inside infolist repeatable entry

I've enable prevent lazy loading like this in providers Model::preventLazyLoading(! $this->app->isProduction());
I create a relationship manager and I display the data in infolist. but when it comes to repeatable entry like below example, I always got this error Attempted to lazy load [customer] on model [App\Models\Reply] but lazy loading is disabled.

protected static string $relationship = 'comments';

public function infolist(Infolist $infolist): Infolist
{
    return $infolist
        ->schema([
            // ...

            Infolists\Components\RepeatableEntry::make('replies')
                ->schema([
                    Infolists\Components\TextEntry::make('customer.name'),
                ]),
        ]);
}

// Comment model
public function replies(): HasMany
{
    return $this->hasMany(Reply::class);
}

// Reply model
public function customer(): BelongsTo
{
    return $this->belongsTo(Customer::class);
}

I can put protected $with = ['customer']; inside Model, but it's not a great solution IMO, so what should be the best way to eager load the relationship
Solution
Yes, so helpful.. Now I use ->modifyQueryUsing() and load relationship. it's working now, thanks
Was this page helpful?