FilamentF
Filament12mo ago
lbar

modal form passing value from the action

In my view I have the following action:
{{ ($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();
       )
[...]

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();
           })
])
[...]


Any clue on how to archive that?
Thank you
Solution
try only this

return 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')
            );
    })
    ->steps([
        Step::make('Documents')
            ->schema([
                Radio::make('member_certificates')
            ]),
    ]);
Was this page helpful?