route('recipe'); if (! $recipe instanceof RecipeDto) { throw ValidationException::withMessages([ 'recipe' => ['The recipe is invalid.'], ]); } $existingPicture = $recipe->picture !== null ? new StorageFilePath($recipe->picture) : null; $picture = null; if ($this->hasFile('picture')) { $picture = $this->storeFile($this->file('picture')); } elseif ($existingPicture !== null) { $picture = $existingPicture; } return new UpdateRecipeInput( id: $recipe->getId(), name: $this->string('name')->trim()->value(), seoTitle: $this->string('seo_title')->trim()->value(), seoDescription: $this->string('seo_description')->trim()->value(), isPublished: $this->boolean('is_published'), productCategory: $this->enum('product_category', ProductCategory::class, ProductCategory::HARD_BOILED_EGGS), consomptionTime: $this->enum('consomption_time', ConsumptionTime::class, ConsumptionTime::BREAK_FAST_BRUNCH), inspiration: $this->enum('inspiration', Inspiration::class, Inspiration::FRENCH_COOKING), season: $this->enum('season', Season::class, Season::ALL_YEAR), description: $this->filled('description') ? $this->string('description')->trim()->value() : null, details: $this->filled('details') ? $this->string('details')->trim()->value() : null, ingredientsList: $this->string('ingredients_list')->trim()->value(), preparationSteps: $this->string('preparation_steps')->trim()->value(), tipsAndAdvices: $this->filled('tips_and_advices') ? $this->string('tips_and_advices')->trim()->value() : null, picture: $picture, pictureAlt: $this->string('picture_alt')->trim()->value(), pictureTitle: $this->string('picture_title')->trim()->value(), products: array_filter($this->array('products'), fn ($product) => is_string($product)), ); } public function rules(): array { return array_merge(parent::rules(), [ 'picture' => [ 'sometimes', Rule::imageFile() ->max(self::MAX_FILE_SIZE_KB) ->dimensions( Rule::dimensions() ->width(static::PICTURE_WIDTH) ->height(static::PICTURE_HEIGHT) ), ], ]); } }