fix: 🐛 resolve error when image is selected and saved

This commit is contained in:
Corentin Huet 2026-05-13 15:19:09 +02:00
parent 42d09e8965
commit 74853687f3
5 changed files with 18 additions and 5 deletions

View file

@ -219,7 +219,7 @@ abstract class UpdateMiniCrudRequest extends FormRequest
if (Arr::exists($this->input("data.$iptName.value"), 'picture')) { if (Arr::exists($this->input("data.$iptName.value"), 'picture')) {
$rules = array_merge($rules, [ $rules = array_merge($rules, [
"data.$iptName.value.picture" => "required|array", "data.$iptName.value.picture" => "required|array",
"data.$iptName.value.picture.path" => "required|image|mimes:png,jpg,jpeg|dimensions:width=620,height=348", "data.$iptName.value.picture.path" => "required",
"data.$iptName.value.picture.alt" => "required|string|between:3,255", "data.$iptName.value.picture.alt" => "required|string|between:3,255",
"data.$iptName.value.picture.title" => "required|string|between:3,255", "data.$iptName.value.picture.title" => "required|string|between:3,255",
]); ]);

View file

@ -184,6 +184,13 @@ trait MiniCrudModel
} }
break; break;
case InputType::selectImageVideo->value: case InputType::selectImageVideo->value:
if (isset($data[$o]['value']['picture']) && $data[$o]['value']['picture']['path'] instanceof \Illuminate\Http\UploadedFile) {
$data[$o]['value']['picture']['path'] = \preg_replace(
'/^\/|^/',
'',
FileStorageHelper::storeFile($this, $data[$o]['value']['picture']['path'], true)
);
}
break; break;
default: default:
throw new \ErrorException(sprintf( throw new \ErrorException(sprintf(

View file

@ -293,6 +293,10 @@ return new class extends Migration
'inputType' => InputType::selectImageVideo->value, 'inputType' => InputType::selectImageVideo->value,
'value' => '', 'value' => '',
'validate' => 'required|array', 'validate' => 'required|array',
'dimensions' => [
'width' => 620,
'height' => 348
],
'required' => true 'required' => true
], ],
'discover_title_1' => [ 'discover_title_1' => [

View file

@ -257,6 +257,8 @@
'name' => $k, 'name' => $k,
'value' => old("data.{$k}.value", $input['value'] ?? null), 'value' => old("data.{$k}.value", $input['value'] ?? null),
'required' => isset($input['required']) ? !empty($input['required']) : true, 'required' => isset($input['required']) ? !empty($input['required']) : true,
'width' => $input['dimensions']['width'],
'height' => $input['dimensions']['height'],
'model' => $model ?? null, 'model' => $model ?? null,
'helper' => 'helper' =>
__('crud.minicrud.text_warning') . __('crud.minicrud.text_warning') .

View file

@ -89,13 +89,13 @@
@include('bo.partials.inputs.varchar-picture', [ @include('bo.partials.inputs.varchar-picture', [
'id' => sprintf("%sPicture", $id), 'id' => sprintf("%sPicture", $id),
'name' => "data[$name][value][picture][path]", 'name' => "data[$name][value][picture][path]",
'width' => 500, 'width' => $width,
'height' => 500, 'height' => $height,
'model' => $model ?? null, 'model' => $model ?? null,
'value' => $model->data[$name]['value']['picture']['path'] ?? null, 'value' => $model->data[$name]['value']['picture']['path'] ?? null,
'helper' => __('crud.minicrud.dimensions_must_be', [ 'helper' => __('crud.minicrud.dimensions_must_be', [
'width' => 500, 'width' => $width,
'height' => 500, 'height' => $height,
]), ]),
'required' => true, 'required' => true,
'preview' => false, 'preview' => false,