F
Filament13mo ago
ddoddsr

V2 to V3 Action with Form adapt to changes

What I am trying to do: Have an action button in a custom page that displays a form with a select and then calls a function with the result of the select What I did so far was working in V2, and I tried two more actions, Nted in the code comments
public function genWallAction(): Action
{
return Action::make('genWallPdf')
->label('Generate Wall PDF')
// Original working v2 action
// ->action('genWallPdf')

// from example
// ->action(Closure::fromCallable([$this, 'genWallPdf']))

//another try
->action(function (array $data) {
$this->genWallPdf($data);
})

->form([
Select::make('location')
->options(Location::query()->pluck('name', 'id'))
->required()
->default(1),
]);
}
public function genWallAction(): Action
{
return Action::make('genWallPdf')
->label('Generate Wall PDF')
// Original working v2 action
// ->action('genWallPdf')

// from example
// ->action(Closure::fromCallable([$this, 'genWallPdf']))

//another try
->action(function (array $data) {
$this->genWallPdf($data);
})

->form([
Select::make('location')
->options(Location::query()->pluck('name', 'id'))
->required()
->default(1),
]);
}
The button show up with {{ $this->genWallAction }} in the blade file. I get the error message: https://flareapp.io/share/47qKp0Bm
Flare
Too few arguments to function App\Filament\Pages\Tools::genWallPdf(), 0 passed in /Users/dandodd/Projects/testtrust/vendor/filament/actions/src/Concerns/InteractsWithActions.php on line 320 and exactly 1 expected - The error occurred at http://localhost:8000/admin/tools
1 Reply
ddoddsr
ddoddsrOP13mo ago
Function called by action:
public function genWallPdf($data)
{
$filePath = 'storage/wall.pdf';
$pdf = new WallPdfController;
$pdf->generatePdf($filePath, $data['location']);

Notification::make()
->title('Generation complete.')
->success()
->send();

return response()->download($filePath);
}
public function genWallPdf($data)
{
$filePath = 'storage/wall.pdf';
$pdf = new WallPdfController;
$pdf->generatePdf($filePath, $data['location']);

Notification::make()
->title('Generation complete.')
->success()
->send();

return response()->download($filePath);
}
My issue was that the name that the text in the Action::make('getWallPdf) matched the function I was calling, skipping the form. I think this is referred to in the docs as the Low impact change with Actions under Action execution with forms .
Want results from more Discord servers?
Add your server