F
Filament2mo ago
dyo

Problem getting multiple select value in action modal form

How can I get multiple select values of form method in action method in Action class? I didn't find it when I check in $data at action method function.
Action::make('masuka_label')
->action(function ($record, array $data, $livewire): void {
dd(
$record,
$data,
$livewire
);

$user = auth()->user();

$label = [
'label_id' => $data['label_id'],
'prospek_id' => $record->id,
'prioritas_id' => $user->prioritas_id,
'cms_users_id' => $user->id,
'lembagaId' => $user->lembaga_id,
];

if ($data['label_baru'] == null) {
LabelProspek::updateOrCreate($label, $label);
} else {
$label['label_id'] = Label::create(['label' => $data['label_baru']])->id;
LabelProspek::create($label);
}
})
->fillForm(fn($record) => [
'label_prospek' => $record->label_prospek->pluck('id')
])
->form([
Select::make('label_prospek')
->multiple()
->relationship(
'label_prospek',
'label',
fn(Builder $query) => $query
->whereHas('label_prospek', function (Builder $q) {
return $q->where('cms_users_id', auth()->user()->id);
})
)
->preload(),

TextInput::make('label_baru')
])
->requiresConfirmation(),
Action::make('masuka_label')
->action(function ($record, array $data, $livewire): void {
dd(
$record,
$data,
$livewire
);

$user = auth()->user();

$label = [
'label_id' => $data['label_id'],
'prospek_id' => $record->id,
'prioritas_id' => $user->prioritas_id,
'cms_users_id' => $user->id,
'lembagaId' => $user->lembaga_id,
];

if ($data['label_baru'] == null) {
LabelProspek::updateOrCreate($label, $label);
} else {
$label['label_id'] = Label::create(['label' => $data['label_baru']])->id;
LabelProspek::create($label);
}
})
->fillForm(fn($record) => [
'label_prospek' => $record->label_prospek->pluck('id')
])
->form([
Select::make('label_prospek')
->multiple()
->relationship(
'label_prospek',
'label',
fn(Builder $query) => $query
->whereHas('label_prospek', function (Builder $q) {
return $q->where('cms_users_id', auth()->user()->id);
})
)
->preload(),

TextInput::make('label_baru')
])
->requiresConfirmation(),
9 Replies
dyo
dyo2mo ago
can someone help me?
toeknee
toeknee2mo ago
So you won't get the options because you set it as a relationship so it'd not valid to this record, it will be saved automatically as part of the relationship?
dyo
dyo2mo ago
Sorry I don't get it.. How can I use it in relationship select in modal form, without repeater?
toeknee
toeknee2mo ago
Filament saves the relationships separate and there is no need for the relationship to be in the data because it’s not part of it. Explain in detail what you are trying to do.
dyo
dyo2mo ago
->form([ Select::make('label_prospek') ->multiple() ->relationship( 'label_prospek', 'label', fn(Builder $query) => $query ->whereHas('label_prospek', function (Builder $q) { return $q->where('cms_users_id', auth()->user()->id); }) ) ]) In above class, I want to mutate the relationship data before saving, I need to fill other attributes in the relationship model.
toeknee
toeknee2mo ago
Same principle should apply to a select
dyo
dyo2mo ago
Where should I use method mutateRelationshipDataBeforeCreateUsing()? It returns exception when I tried using it in table action class or in select class.. nevermind, i found the method similar to that, using saveRelationshipsUsing in select class.. thanks for your guidance before @toeknee cheers
Want results from more Discord servers?
Add your server