mutateFormDataUsing not working on CreateAction

Hi, I can't get mutateFormDataUsing to work and mutate my data in a header CreateAction. I saw somebody else had the same issue, but it didn't seem to have been resolved. I've also tried "using", but also not working well. Any tips?
5 Replies
Patrick Boivin
Patrick Boivin16mo ago
It could be a bug, I'm not sure... What are you trying to do? Maybe there's a workaround for your use-case.
Kanalaetxebarria
KanalaetxebarriaOP16mo ago
I'm trying to set the file path of a PDF file by calling a route:
->mutateFormDataUsing(function (array $data): array {
$data['file_path'] = fn () => route('download-pdf', ['id' => Filament::getTenant()->id]);

return $data;
})
->mutateFormDataUsing(function (array $data): array {
$data['file_path'] = fn () => route('download-pdf', ['id' => Filament::getTenant()->id]);

return $data;
})
Where my controller looks like this:
... $pdf = Pdf::loadView('pdfs.pdf', $data);

// Generate a unique filename for the PDF
$filename = 'monthly-report-' . uniqid() . '.pdf';

// Save the PDF to the storage disk
$pdfPath = 'pdfs/' . $filename;
Storage::disk('public')->put($pdfPath, $pdf->output());

return $pdfPath;
... $pdf = Pdf::loadView('pdfs.pdf', $data);

// Generate a unique filename for the PDF
$filename = 'monthly-report-' . uniqid() . '.pdf';

// Save the PDF to the storage disk
$pdfPath = 'pdfs/' . $filename;
Storage::disk('public')->put($pdfPath, $pdf->output());

return $pdfPath;
Patrick Boivin
Patrick Boivin16mo ago
route() is not calling the controller though... it's just returning a url. Did I miss anything?
Kanalaetxebarria
KanalaetxebarriaOP16mo ago
you're right, my bad. After using the Http facade, however, the mutateFormDataUsing method still doesn't get called and nothing changes
Patrick Boivin
Patrick Boivin16mo ago
Yeah, could be a bug, I'm not sure. As a workaround, do you think you could use a lifecycle hook, like afterSave()? https://filamentphp.com/docs/3.x/panels/resources/editing-records#lifecycle-hooks
Want results from more Discord servers?
Add your server