How can I get the uploaded file before saving data

Is there a way to get the uploaded file before saving data to the database in CreateCustomer class that extends CreateRecord
class CreateCustomer extends CreateRecord
{
protected static string $resource = CustomerResource::class;
}
class CreateCustomer extends CreateRecord
{
protected static string $resource = CustomerResource::class;
}
this is the form in resource class
Select::make('group_id')->translateLabel()
->options(Group::pluck('name', 'id'))
->searchable()
->hiddenOn(['edit'])
->required(),
TextInput::make('phone')->translateLabel()
->required()
->maxLength(191),
TextInput::make('email')->translateLabel()
->email()
->maxLength(191),
FileUpload::make('identity'),
Select::make('group_id')->translateLabel()
->options(Group::pluck('name', 'id'))
->searchable()
->hiddenOn(['edit'])
->required(),
TextInput::make('phone')->translateLabel()
->required()
->maxLength(191),
TextInput::make('email')->translateLabel()
->email()
->maxLength(191),
FileUpload::make('identity'),
Solution:
I found a solution, just use
$this->form->getRawState()
$this->form->getRawState()
Jump to solution
6 Replies
Ayman Alhattami
Ayman AlhattamiOP13mo ago
I used
mutateFormDataBeforeCreate(array $data)
mutateFormDataBeforeCreate(array $data)
to catch the data before save and do my customization, I can get all the data of the form fields from $data parameter, but the file upload field data not found in the $data parameter in this function Customizing data before saving
torriv
torriv13mo ago
what do you need to do to the file before saving data to the database?
Ayman Alhattami
Ayman AlhattamiOP13mo ago
I have conditions and based on these conditions I store the data either to the actual table or to another table with the uploaded files
Ayman Alhattami
Ayman AlhattamiOP13mo ago
I also tried
handleRecordCreation
handleRecordCreation
and the same thing, I can get all the data of the form fields from $data parameter, but the file upload field data not found in the $data parameter https://filamentphp.com/docs/3.x/panels/resources/creating-records#customizing-the-creation-process
Solution
Ayman Alhattami
Ayman Alhattami13mo ago
I found a solution, just use
$this->form->getRawState()
$this->form->getRawState()
Want results from more Discord servers?
Add your server