From a590a74cabe199cdba8855ef9735b693140ad4c7 Mon Sep 17 00:00:00 2001 From: Stefan Zwischenbrugger Date: Mon, 30 Mar 2026 17:58:12 +0200 Subject: [PATCH] Fix: HTTP 500 bei Foto ohne Preis (price_decimal NULL + Foto-Validierung) - Migration: price_decimal sicher nullable (Mediathek/Foto-only) - Validierung: mimes statt File::types, max 15360 KB Made-with: Cursor --- .../Requests/ToggleShoppingItemRequest.php | 11 ++++------ .../Requests/UpdateShoppingItemRequest.php | 12 +++++------ ...item_price_logs_price_decimal_nullable.php | 21 +++++++++++++++++++ 3 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 database/migrations/2026_03_31_000000_ensure_item_price_logs_price_decimal_nullable.php diff --git a/app/Http/Requests/ToggleShoppingItemRequest.php b/app/Http/Requests/ToggleShoppingItemRequest.php index 4061cab..0e61343 100644 --- a/app/Http/Requests/ToggleShoppingItemRequest.php +++ b/app/Http/Requests/ToggleShoppingItemRequest.php @@ -2,8 +2,8 @@ namespace App\Http\Requests; +use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; -use Illuminate\Validation\Rules\File; class ToggleShoppingItemRequest extends FormRequest { @@ -25,7 +25,7 @@ class ToggleShoppingItemRequest extends FormRequest /** * Get the validation rules that apply to the request. * - * @return array|string> + * @return array|string> */ public function rules(): array { @@ -37,11 +37,7 @@ class ToggleShoppingItemRequest extends FormRequest 'price_decimal' => ['nullable', 'numeric', 'min:0', 'max:999999.99'], 'tier_min_qty' => ['nullable', 'integer', 'min:2', 'max:999999'], 'tier_price_decimal' => ['nullable', 'numeric', 'min:0', 'max:999999.99'], - 'photo' => [ - 'nullable', - File::types(['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif']) - ->max(15 * 1024), - ], + 'photo' => ['nullable', 'file', 'max:15360', 'mimes:jpeg,jpg,png,gif,webp,heic,heif'], ]; } @@ -63,6 +59,7 @@ class ToggleShoppingItemRequest extends FormRequest 'tier_price_decimal.min' => 'Der Staffelpreis darf nicht negativ sein.', 'tier_price_decimal.max' => 'Der Staffelpreis ist zu gross.', 'photo.max' => 'Das Foto darf maximal 15 MB gross sein.', + 'photo.mimes' => 'Das Foto muss ein Bild sein (jpg, png, gif, webp, heic, heif).', 'photo.uploaded' => 'Das Foto konnte nicht hochgeladen werden. Haeufig: Datei zu gross fuer die PHP-Grenze auf dem Server (upload_max_filesize / post_max_size). Bitte ein kleineres Bild waehlen oder die Server-Limits erhoehen (siehe scripts/apache-einkauf-debian-setup.sh, Abschnitt PHP-Uploads).', ]; } diff --git a/app/Http/Requests/UpdateShoppingItemRequest.php b/app/Http/Requests/UpdateShoppingItemRequest.php index 1249a3f..e76acbb 100644 --- a/app/Http/Requests/UpdateShoppingItemRequest.php +++ b/app/Http/Requests/UpdateShoppingItemRequest.php @@ -2,8 +2,8 @@ namespace App\Http\Requests; +use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; -use Illuminate\Validation\Rules\File; class UpdateShoppingItemRequest extends FormRequest { @@ -20,7 +20,7 @@ class UpdateShoppingItemRequest extends FormRequest } /** - * @return array|string> + * @return array|string> */ public function rules(): array { @@ -33,11 +33,8 @@ class UpdateShoppingItemRequest extends FormRequest 'price_decimal' => ['nullable', 'numeric', 'min:0', 'max:999999.99'], 'tier_min_qty' => ['nullable', 'integer', 'min:2', 'max:999999'], 'tier_price_decimal' => ['nullable', 'numeric', 'min:0', 'max:999999.99'], - 'photo' => [ - 'nullable', - File::types(['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif']) - ->max(15 * 1024), - ], + // max = Kilobyte (15360 = 15 MB). mimes: zuverlaessiger als File::types bei iOS/Mediathek-MIME. + 'photo' => ['nullable', 'file', 'max:15360', 'mimes:jpeg,jpg,png,gif,webp,heic,heif'], ]; } @@ -59,6 +56,7 @@ class UpdateShoppingItemRequest extends FormRequest 'tier_price_decimal.min' => 'Der Staffelpreis darf nicht negativ sein.', 'tier_price_decimal.max' => 'Der Staffelpreis ist zu gross.', 'photo.max' => 'Das Foto darf maximal 15 MB gross sein.', + 'photo.mimes' => 'Das Foto muss ein Bild sein (jpg, png, gif, webp, heic, heif).', 'photo.uploaded' => 'Das Foto konnte nicht hochgeladen werden. Haeufig: Datei zu gross fuer die PHP-Grenze auf dem Server (upload_max_filesize / post_max_size). Bitte ein kleineres Bild waehlen oder die Server-Limits erhoehen (siehe scripts/apache-einkauf-debian-setup.sh, Abschnitt PHP-Uploads).', ]; } diff --git a/database/migrations/2026_03_31_000000_ensure_item_price_logs_price_decimal_nullable.php b/database/migrations/2026_03_31_000000_ensure_item_price_logs_price_decimal_nullable.php new file mode 100644 index 0000000..3ec3ac9 --- /dev/null +++ b/database/migrations/2026_03_31_000000_ensure_item_price_logs_price_decimal_nullable.php @@ -0,0 +1,21 @@ +