How to dehydrate FileUpload?

Dehydration is the process which gets data from fields, and transforms it. It runs when you call the form's getState() method.
However, when using $this->form->getState() it triggers the validation that affects the whole form. How to bypass the Form validation (and just validate the current state only) and just get the state value of the file?
FileUpload::make('file')
->afterStateUpdated(function(FileUpload $component, $state){
dd($state);
});
FileUpload::make('file')
->afterStateUpdated(function(FileUpload $component, $state){
dd($state);
});
11 Replies
LeandroFerreira
$livewire->validateOnly('file') ?
vahnmarty
vahnmartyOP2y ago
I need the state value. The one that makes the file be uploaded in the storage folder ( not just in livewire-tmp) and returns the string of file path . The form->getState() did that. Now I'm looking for a method that does that without using form->getState().
LeandroFerreira
what about getRawState()?
vahnmarty
vahnmartyOP2y ago
->getRawState() still returns that Livewire/TemporaryUploadFile and the file is not uploaded .
LeandroFerreira
?
->afterStateUpdated(function ($component) {
$component->saveUploadedFiles();
})
->afterStateUpdated(function ($component) {
$component->saveUploadedFiles();
})
vahnmarty
vahnmartyOP2y ago
That worked, any idea on how to get the file name? I got null
LeandroFerreira
$component->getState() ?
vahnmarty
vahnmartyOP2y ago
When using $component->getState() I got this:
array:1 [▼ // php:46
"f6bd9206-a4f9-472b-b7de-c43fb27ba86e" => "learning_docs/1/sample2.pdf"
]
array:1 [▼ // php:46
"f6bd9206-a4f9-472b-b7de-c43fb27ba86e" => "learning_docs/1/sample2.pdf"
]
All I need is ["learning_docs/1/sample2.pdf"] without UUID. Do I just need to do it manually by using a foreach?
LeandroFerreira
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
vahnmarty
vahnmartyOP2y ago
Cool, it worked!
->afterStateUpdated(function(FileUpload $component, $state){
$component->saveUploadedFiles();
$files = Arr::flatten($component->getState());
->afterStateUpdated(function(FileUpload $component, $state){
$component->saveUploadedFiles();
$files = Arr::flatten($component->getState());
LeandroFerreira
nice 👌
Want results from more Discord servers?
Add your server