undercode
undercode
FFilament
Created by undercode on 9/19/2023 in #❓┊help
Prevent image saving with FileUpload (v2)
Hi! I have a FileUpload component in an action form with multiple(). When I submit the modal form I want to save only some of the files sent. I've tried to remove some from $data, but it doesn't work. Any idea?
Tables\Actions\Action::make('import_images')
->button()
->color('warning')
->form([
Forms\Components\FileUpload::make('files')
->disk('private')
->directory('applicant_pictures')
->image()
->imageResizeMode('cover')
->imageResizeTargetWidth(768)
->imageResizeTargetHeight(1024)
->imageCropAspectRatio('3:4')
->imagePreviewHeight('40px')
->disablePreview()
->maxFiles(10)
->getUploadedFileNameForStorageUsing(function (TemporaryUploadedFile $file): string {
$preffix = 'ap_';
return (string) str($file->hashName())->prepend($preffix);
})
->visibility('private')
->multiple(true)
->storeFileNamesIn('original_file_names')
->panelLayout('grid'),
])
->action(function ($data) {
$fileIndex = 0;
foreach ($data['original_file_names'] as $filepath => $originalName) {
$dni = Str::upper(pathinfo($originalName, PATHINFO_FILENAME));
$applicant = Applicant::where('dni', $dni)->first();
$pictures = [];
if ($applicant) {
$pictures[] = [
'path' => $filepath,
];
} else {
unset($data['original_file_names'][$filepath]);
unset($data['files'][$fileIndex]);
}

$fileIndex += 1;

if (count($pictures) > 0) {
$applicant->pictures()->createMany($pictures);
}
}
}),
Tables\Actions\Action::make('import_images')
->button()
->color('warning')
->form([
Forms\Components\FileUpload::make('files')
->disk('private')
->directory('applicant_pictures')
->image()
->imageResizeMode('cover')
->imageResizeTargetWidth(768)
->imageResizeTargetHeight(1024)
->imageCropAspectRatio('3:4')
->imagePreviewHeight('40px')
->disablePreview()
->maxFiles(10)
->getUploadedFileNameForStorageUsing(function (TemporaryUploadedFile $file): string {
$preffix = 'ap_';
return (string) str($file->hashName())->prepend($preffix);
})
->visibility('private')
->multiple(true)
->storeFileNamesIn('original_file_names')
->panelLayout('grid'),
])
->action(function ($data) {
$fileIndex = 0;
foreach ($data['original_file_names'] as $filepath => $originalName) {
$dni = Str::upper(pathinfo($originalName, PATHINFO_FILENAME));
$applicant = Applicant::where('dni', $dni)->first();
$pictures = [];
if ($applicant) {
$pictures[] = [
'path' => $filepath,
];
} else {
unset($data['original_file_names'][$filepath]);
unset($data['files'][$fileIndex]);
}

$fileIndex += 1;

if (count($pictures) > 0) {
$applicant->pictures()->createMany($pictures);
}
}
}),
4 replies
FFilament
Created by undercode on 4/11/2023 in #❓┊help
DatePicker "hintAction" error: Xdebug has detected a possible infinite loop
When I set a "hintAction" in a DatePicker component I get "possible infinite loop" error which is gone after removing it or setting to null. This is the error I get: https://flareapp.io/share/dPbqNp4m#F257 And this is an example code:
DatePicker::make('assistant_date')
->label('Fecha')
->displayFormat('D, j [de] M. [de] Y')
->withoutTime()
->disabled(fn (Closure $get) => (int) $get('assistant') === 0)
->hintAction(
Action::make('copy_date')
->action(null)
)
DatePicker::make('assistant_date')
->label('Fecha')
->displayFormat('D, j [de] M. [de] Y')
->withoutTime()
->disabled(fn (Closure $get) => (int) $get('assistant') === 0)
->hintAction(
Action::make('copy_date')
->action(null)
)
2 replies