saveRelationshipsUsing on custom page form.

I have a custom page with attachment relationship like
public function form(Form $form): Form
{
return $form->([
TextInput::make('name'),
Repeater::make('cover_images')
->label('Covers')
->relationship('coverPhotos')
->schema([
TextInput::make('image')
->label('File Path')
->required(),
TextInput::make('note')
->label('Note'),
])
->saveRelationshipsUsing(function ($state) {
dd('saveRelationshipsUsing', $state);
})
])
}

public function saveAction(): Action
{
return Action::make('save')->action(fn() => //...);
}
public function form(Form $form): Form
{
return $form->([
TextInput::make('name'),
Repeater::make('cover_images')
->label('Covers')
->relationship('coverPhotos')
->schema([
TextInput::make('image')
->label('File Path')
->required(),
TextInput::make('note')
->label('Note'),
])
->saveRelationshipsUsing(function ($state) {
dd('saveRelationshipsUsing', $state);
})
])
}

public function saveAction(): Action
{
return Action::make('save')->action(fn() => //...);
}
Blade file
<div class="mt-6 gap-2 flex">
{{ $this->form }}
{{ $this->saveAction }}
</div>
<div class="mt-6 gap-2 flex">
{{ $this->form }}
{{ $this->saveAction }}
</div>
I don't know why the saveRelationshipsUsing is not trigger, is there any thing I missed out ? Thank you
Solution:
are you using this in your saveAction? ```php $model = YourModel::create($this->form->getState()); $this->form->model($model)->saveRelationships();...
Jump to solution
2 Replies
Solution
LeandroFerreira
are you using this in your saveAction?
$model = YourModel::create($this->form->getState());
$this->form->model($model)->saveRelationships();
$model = YourModel::create($this->form->getState());
$this->form->model($model)->saveRelationships();
https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component#passing-the-form-model-after-the-form-has-been-submitted
Asmit
AsmitOP2w ago
Thank you @Leandro Ferreira this solve my requirement.

Did you find this page helpful?