authService->check(); } public function toCreateRecipeInput(): CreateRecipeInput { $picture = null; if ($this->hasFile('picture')) { $picture = $this->storeFile($this->file('picture')); } return new CreateRecipeInput( 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)), ); } protected function storeFile(UploadedFile $file): StorageFilePath { return $this->storageService->storeUploadedOntoDisk( $file, $this->s3Disk->disk ); } /** * Prepare the data for validation. */ protected function prepareForValidation(): void { $this->merge([ 'name' => $this->string('name')->trim()->value(), 'seo_title' => $this->string('seo_title')->trim()->value(), 'seo_description' => $this->string('seo_description')->trim()->value(), 'picture_alt' => $this->string('picture_alt')->trim()->value(), 'picture_title' => $this->string('picture_title')->trim()->value(), ]); } /** * Get the validation rules that apply to the request. * * @return array|string> */ public function rules(): array { return [ 'name' => ['required', 'string', 'min:3', 'max:255'], 'seo_title' => ['required', 'string', 'between:45,70'], 'seo_description' => ['required', 'string', 'between:50,160'], 'is_published' => ['boolean'], 'product_category' => ['required', new Enum(ProductCategory::class)], 'consomption_time' => ['required', new Enum(ConsumptionTime::class)], 'inspiration' => ['required', new Enum(Inspiration::class)], 'season' => ['required', new Enum(Season::class)], 'description' => ['nullable', 'string', 'min:15', new MaxStrippedLength(800)], 'details' => ['nullable', 'string', 'min:15', new MaxStrippedLength(255)], 'ingredients_list' => ['required', 'string', 'min:15', new MaxStrippedLength(1000)], 'preparation_steps' => ['required', 'string', 'min:15', new MaxStrippedLength(2000)], 'tips_and_advices' => ['nullable', 'string', 'min:15', new MaxStrippedLength(500)], 'picture' => [ 'required', Rule::imageFile() ->max(self::MAX_FILE_SIZE_KB) ->dimensions( Rule::dimensions() ->width(static::PICTURE_WIDTH) ->height(static::PICTURE_HEIGHT) ), ], 'picture_alt' => ['required', 'string', 'min:4', 'max:75'], 'picture_title' => ['required', 'string', 'min:4', 'max:75'], 'products' => ['nullable', 'array'], 'products.*' => ['string', 'uuid', 'exists:products,id'], ]; } /** * Get custom attributes for validator errors. * * @return array */ public function attributes(): array { return [ 'name' => trans('validation.attributes.name'), 'seo_title' => trans('validation.attributes.seo_title'), 'seo_description' => trans('validation.attributes.seo_description'), 'is_published' => trans('validation.attributes.is_published'), 'product_category' => trans('validation.attributes.product_category'), 'consomption_time' => trans('validation.attributes.consomption_time'), 'inspiration' => trans('validation.attributes.inspiration'), 'season' => trans('validation.attributes.season'), 'description' => trans('validation.attributes.description'), 'details' => trans('validation.attributes.details'), 'ingredients_list' => trans('validation.attributes.ingredients_list'), 'preparation_steps' => trans('validation.attributes.preparation_steps'), 'tips_and_advices' => trans('validation.attributes.tips_and_advices'), 'picture' => trans('validation.attributes.picture'), 'picture_alt' => trans('validation.attributes.picture_alt'), 'picture_title' => trans('validation.attributes.picture_title'), 'products' => trans('validation.attributes.associated_products'), ]; } }