Relation Manager with repeater and pivot
I Hi, I have the following:
class RewardsRelationManager extends RelationManager {
protected static string $relationship = 'rewards';
[....]
Forms\Components\Repeater::make('currencies')
->relationship()
->schema([
Forms\Components\Select::make('currency_id')
->label('Currency')
->options(fn () => \App\Models\Currency::pluck('name', 'id'))
->required(),
Forms\Components\TextInput::make('amount')
->numeric()
->required()
->minValue(1)
->label('Amount'),
])
In the Reward model:
public function currencies()
{
return $this->belongsToMany(Currency::class)
->withPivot('amount');
}
The migration of the pivot is:
Schema::create('reward_currency', function (Blueprint $table) {
$table->foreignId('reward_id')->constrained('rewards')->onDelete('cascade');
$table->unsignedTinyInteger('currency_id');
$table->foreign('currency_id')->references('id')->on('currencies')->onUpdate('cascade');
$table->unsignedInteger('amount')->nullable();
$table->primary(['reward_id', 'currency_id']);
});
The data in pivot, is shown in the repeater, no problem at all. But when I try to update or create data, there is no changes or rows created in the database.
I tried some approachs with mutateRelationshipDataBeforeSaveUsing, but no luck. Any ideas?
Thanks1 Reply
No ideas?