F
Filament4d ago
lbar

modal form passing value from the action

In my view I have the following action:
{{ ($this->subscribeMemberAction)(['member_id' => $member->id]) }}
{{ ($this->subscribeMemberAction)(['member_id' => $member->id]) }}
this work pretty well, and I'm able to fetch my data from fillForm on the component:
return Action::make('subscribeMember')
->fillForm(function (array $arguments){
return Member::where('id', '=', $arguments['member_id'])->first()->toArray();
)
[...]
return Action::make('subscribeMember')
->fillForm(function (array $arguments){
return Member::where('id', '=', $arguments['member_id'])->first()->toArray();
)
[...]
but I need to pre-fetch some options (extracting them from database) using the same $arguments['member_id']. So something like this, but here the $arguments is not available
[...]
->schema([
Radio::make('member_certificates')
->options(function ($arguments){
// here $arguments['member_id'] is not available
return MemberCertificate::where('member_id', '=', $arguments['member_id'])->pluck('id','expire_Date')->toArray();
})
])
[...]
[...]
->schema([
Radio::make('member_certificates')
->options(function ($arguments){
// here $arguments['member_id'] is not available
return MemberCertificate::where('member_id', '=', $arguments['member_id'])->pluck('id','expire_Date')->toArray();
})
])
[...]
Any clue on how to archive that? Thank you
1 Reply
LeandroFerreira
try
Actions\Action::make('subscribeMember')
->mountUsing(function (Form $form, array $arguments) {
$form->getComponent($form->getStatePath().'.member_certificates')
->options(fn () => MemberCertificate::whereMemberId($arguments['member_id'])
->pluck('id', 'expire_Date')
);
})
->form([
Radio::make('member_certificates'),
])
->action(function () {...})
Actions\Action::make('subscribeMember')
->mountUsing(function (Form $form, array $arguments) {
$form->getComponent($form->getStatePath().'.member_certificates')
->options(fn () => MemberCertificate::whereMemberId($arguments['member_id'])
->pluck('id', 'expire_Date')
);
})
->form([
Radio::make('member_certificates'),
])
->action(function () {...})

Did you find this page helpful?