F
Filament17mo ago
Bloom

Custom Action modal call back function NULL

return [
Actions\Action::make('Withdraw')
->mountUsing(fn (Forms\ComponentContainer $form, PigmyCustomer $record) => $form->fill([
'Id' => $record->id,
]))
->action(function (PigmyCustomer $record,array $data): void {
if (isset($data['withdrawal_date'])) {
dd($record->id);
$record->update([
'withdrawal_date' => $data['withdrawal_date'],
]);
}
})
->form([
Forms\Components\TextInput::make('Id')
->label('Pigmy Customer Id')
->required(),
Forms\Components\DatePicker::make('withdrawal_date')
->label('Withdrawal date')
->default(now())
->required(),
])
];
return [
Actions\Action::make('Withdraw')
->mountUsing(fn (Forms\ComponentContainer $form, PigmyCustomer $record) => $form->fill([
'Id' => $record->id,
]))
->action(function (PigmyCustomer $record,array $data): void {
if (isset($data['withdrawal_date'])) {
dd($record->id);
$record->update([
'withdrawal_date' => $data['withdrawal_date'],
]);
}
})
->form([
Forms\Components\TextInput::make('Id')
->label('Pigmy Customer Id')
->required(),
Forms\Components\DatePicker::make('withdrawal_date')
->label('Withdrawal date')
->default(now())
->required(),
])
];
In my custom view i have made custom action so that i can update withdrawal_date, i have tried the above code but PigmyCustomer $record is not receiving the current customer data and return NULL
9 Replies
bwurtz999
bwurtz99917mo ago
Is the Pigmy Customer ID being set properly when the view initially loads? Have you tried dd($record)
Bloom
BloomOP17mo ago
->mountUsing(fn (Forms\ComponentContainer $form, PigmyCustomer $record)
->mountUsing(fn (Forms\ComponentContainer $form, PigmyCustomer $record)
Argument #2 ($record) must be of type App\Models\PigmyCustomer, null given I am getting the above error
bwurtz999
bwurtz99917mo ago
If you are using a custom view, are you also using a custom page? In that case, you would have to set the PigmyCustomer yourself. Probably in mount()
Bloom
BloomOP17mo ago
Yes i made custom page
Bloom
BloomOP17mo ago
here 'view-pigmy-customer-details' is the custom page
bwurtz999
bwurtz99917mo ago
From the docs, it looks like you only pass the $form to ->mountUsing()
->mountUsing(fn (Forms\ComponentContainer $form) => $form->fill([
'authorId' => $this->record->author->id,
]))
->mountUsing(fn (Forms\ComponentContainer $form) => $form->fill([
'authorId' => $this->record->author->id,
]))
and then call $this->record to access the record
Bloom
BloomOP17mo ago
it is working now
Bloom
BloomOP17mo ago
Filament
Actions - Table Builder - Filament
The elegant TALL stack table builder for Laravel artisans.
Bloom
BloomOP17mo ago
i looked it from this doc
->mountUsing(fn (Forms\ComponentContainer $form, User $record) => $form->fill([
'authorId' => $record->author->id,
->mountUsing(fn (Forms\ComponentContainer $form, User $record) => $form->fill([
'authorId' => $record->author->id,
where User model is used Thanks alot
Want results from more Discord servers?
Add your server