© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
6 replies
wyChoong

how to eager load in relationship manager

i have these models
class Company extends Model
{
    public function events(): BelongsToMany
    {
        return $this->belongsToMany(Event::class)
            ->using(CompanyEvent::class)
            ->as('events')
            ->withPivot([
                'profile_id'
            ]);
    }

    public function profiles(): HasMany
    {
        return $this->hasMany(CompanyProfile::class);
    }
}

class Event extends Model
{
    public function companies(): BelongsToMany
    {
        return $this->belongsToMany(Company::class)
            ->as('companies')
            ->using(CompanyEvent::class)
            ->withPivot([
                'profile_id',
            ]);
    }
}

class CompanyEvent extends Pivot
{
    protected $fillable = [
        'company_id', 'event_id', 'profile_id',
    ];

    public function profile(): BelongsTo
    {
        return $this->belongsTo(CompanyProfile::class);
    }
}
class Company extends Model
{
    public function events(): BelongsToMany
    {
        return $this->belongsToMany(Event::class)
            ->using(CompanyEvent::class)
            ->as('events')
            ->withPivot([
                'profile_id'
            ]);
    }

    public function profiles(): HasMany
    {
        return $this->hasMany(CompanyProfile::class);
    }
}

class Event extends Model
{
    public function companies(): BelongsToMany
    {
        return $this->belongsToMany(Company::class)
            ->as('companies')
            ->using(CompanyEvent::class)
            ->withPivot([
                'profile_id',
            ]);
    }
}

class CompanyEvent extends Pivot
{
    protected $fillable = [
        'company_id', 'event_id', 'profile_id',
    ];

    public function profile(): BelongsTo
    {
        return $this->belongsTo(CompanyProfile::class);
    }
}


the
company_event
company_event
table is unique by 3 columns
now in my
EventResource->CompaniesRelationManager
EventResource->CompaniesRelationManager
, I would want to display the profile name, i tried
Tables\Columns\TextColumn::make('companies.profile.name')
Tables\Columns\TextColumn::make('companies.profile.name')
, while it works it is having N+1
image.png
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 eager load in Relation Manager?
FilamentFFilament / ❓┊help
3y ago
How to Eager Load Nested Relationship in table builder
FilamentFFilament / ❓┊help
2y ago
How to eager load relationship inside infolist repeatable entry
FilamentFFilament / ❓┊help
2y ago
Table apply filter in a eager load relationship
FilamentFFilament / ❓┊help
2y ago