AutoSave FileUpload #10994
Unanswered
vicargoexpress
asked this question in
Help
AutoSave FileUpload
#10994
Replies: 1 comment
-
Hey ! FileUpload::make('image')
->label('Image')
->image()
->disk('public')
->directory('advertising-images')
->storeFileNamesIn('original_filename')
->preserveFilenames()
->deleteUploadedFileUsing(function (Get $get, $state, $livewire) {
$record = $livewire->getRecord();
if ($record && $record->image) {
Storage::disk('public')->delete($record->image);
$record->update(['image' => null]);
Notification::make()
->title('Image supprimée')
->success()
->body('L\'image a été supprimée avec succès.')
->send();
}
})
->afterStateUpdated(function ($state, $component, $livewire) {
if ($state instanceof \Livewire\Features\SupportFileUploads\TemporaryUploadedFile && $record = $livewire->getRecord()) {
$record = $livewire->getRecord();
$path = $state->storeAs(
'advertising-images',
$state->getClientOriginalName(),
'public'
);
$record->update(['image' => $path]);
Notification::make()
->title('Image uploadée')
->success()
->body('L\'image a été uploadée avec succès.')
->send();
}
}), |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How do I autosave the form. When the user changes the images? No need to always click save!
Beta Was this translation helpful? Give feedback.
All reactions