© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•11mo ago•
5 replies
MikePageDev

Repeater HasMany

I have followed the docs regarding the BelongsToMany relationship. I have managed to get this to work on a custom page, but now I am trying to add it to a Resource. The edit page is not displaying existing relationships, and Create and Edit are not saving new relationships to the pivot table.

My pivot table does have an incremental
id
id
column.

Here is my
repeater
repeater
code
Repeater::make('federationOpponent')
                        ->columns(1)
                        ->model(Opponent::class)
                        ->relationship('federationOpponent')
                        ->schema([
                            Select::make('federation_id')
                                ->relationship('federation', 'tag')
                                ->required()
                                ->distinct(),
                            TextInput::make('federation_code')
                                ->required(),
                        ])
                        ->addActionLabel('Add Federation')
Repeater::make('federationOpponent')
                        ->columns(1)
                        ->model(Opponent::class)
                        ->relationship('federationOpponent')
                        ->schema([
                            Select::make('federation_id')
                                ->relationship('federation', 'tag')
                                ->required()
                                ->distinct(),
                            TextInput::make('federation_code')
                                ->required(),
                        ])
                        ->addActionLabel('Add Federation')


Here are my model relationships
class Opponent extends Model
{
    public function federationOpponent(): HasMany
    {
        return $this->hasMany(FederationOpponent::class, 'opponent_id');
    }
}

class FederationOpponent extends Pivot
{
    protected $table = 'federation_opponent';
    protected $fillable = ['federation_id', 'opponent_id', 'federation_code'];

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

    public function opponent(): BelongsTo
    {
        return $this->belongsTo(Opponent::class);
    }
}
class Opponent extends Model
{
    public function federationOpponent(): HasMany
    {
        return $this->hasMany(FederationOpponent::class, 'opponent_id');
    }
}

class FederationOpponent extends Pivot
{
    protected $table = 'federation_opponent';
    protected $fillable = ['federation_id', 'opponent_id', 'federation_code'];

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

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


Any ideas? Have I missed something?
Solution
so:

Repeater::make('federationOpponent')
    ->columns(1)
    ->relationship('federationOpponent')
    ->schema([
        Select::make('federation_id')
            ->relationship('federation', 'tag')
            ->required()
            ->distinct(),
        TextInput::make('federation_code')
            ->required(),
    ])
    ->addActionLabel('Add Federation')
Repeater::make('federationOpponent')
    ->columns(1)
    ->relationship('federationOpponent')
    ->schema([
        Select::make('federation_id')
            ->relationship('federation', 'tag')
            ->required()
            ->distinct(),
        TextInput::make('federation_code')
            ->required(),
    ])
    ->addActionLabel('Add Federation')
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
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Repeater with hasMany
FilamentFFilament / ❓┊help
3y ago
Repeater HasMany relationship error
FilamentFFilament / ❓┊help
3y ago
Repeater with hasMany relationship
FilamentFFilament / ❓┊help
3y ago
Filament Manage Related with hasMany and hasMany with Repeater
FilamentFFilament / ❓┊help
3y ago