F
Filament2y ago
Abi

save model relationships on a standalone form builder with repeater

I have the following standalone form. How do I go about saving the relations on the model?
public function mount()
{
$this->customer = User::find(1);

$this->form->fill([
'notifications' => $this->customer->userNotifications
]);
}

public function getFormSchema(): array
{
return [
Repeater::make('notifications')
->schema([
TextInput::make('notification')
->hiddenLabel()
->columnSpan(2)
->disabled(),
Toggle::make('email')->label('E-mail'),
Toggle::make('sms')->label('Text')
])->addable(false)->columns(4)->reorderable(false)->deletable(false)->hiddenLabel()
];
}

public function getFormModel(): Model|string|null
{
return $this->customer;
}

public function save()
{
$this->form->model($this->customer)->saveRelationships();
}
public function mount()
{
$this->customer = User::find(1);

$this->form->fill([
'notifications' => $this->customer->userNotifications
]);
}

public function getFormSchema(): array
{
return [
Repeater::make('notifications')
->schema([
TextInput::make('notification')
->hiddenLabel()
->columnSpan(2)
->disabled(),
Toggle::make('email')->label('E-mail'),
Toggle::make('sms')->label('Text')
])->addable(false)->columns(4)->reorderable(false)->deletable(false)->hiddenLabel()
];
}

public function getFormModel(): Model|string|null
{
return $this->customer;
}

public function save()
{
$this->form->model($this->customer)->saveRelationships();
}
calling saveRelationships() seems to do nothing. I checked the queries executed and there aren't any update statement. Any ideas what the issue may be? I looked into the docs and couldn't figure out.
2 Replies
Dennis Koch
Dennis Koch2y ago
Use ->relationship() on your Repeater
Abi
AbiOP2y ago
ok, let me give that a try
Want results from more Discord servers?
Add your server