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
Here is my
Here are my model relationships
Any ideas? Have I missed something?
My pivot table does have an incremental
idid column.Here is my
repeaterrepeater codeRepeater::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')