check(); } /** * Prepare the data for validation. * * @return void */ protected function prepareForValidation() { $this->merge([ 'slug' => Str::slug(strip_tags($this->name)), 'status' => $this->status ? true : false, ]); $this->mergePicture('picture'); $this->mergePicture('picture_thumbnail'); } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { $rules = [ 'seo_title' => 'required|min:3|max:70', 'seo_description' => 'required|min:50|max:160', 'name' => 'required|min:3|max:255', 'slug' => 'unique_translation:recipes', 'picture_alt' => 'required|min:3|max:255', 'picture_title' => 'required|min:3|max:255', 'picture_thumbnail_alt' => 'required|min:3|max:255', 'picture_thumbnail_title' => 'required|min:3|max:255', 'ingredients' => [ // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed 'present', 'array', function ($attribute, array $value, $fail) { if (1 > count($value)) { $fail(\trans('You must fill in at least 1 line of ingredients.')); } } ], 'ingredients.*' => 'nullable|array', 'ingredients.*.header' => 'nullable|string|min:3|max:255', 'ingredients.*.value' => 'nullable|string|min:3|max:255', 'teaser' => 'required|min:50|max:160', 'steps' => 'required|string|min:15', 'difficulty' => [new Enum(DifficultyEnum::class)], 'preparation' => 'required|numeric|min:1|max:1440', 'duration' => 'required|numeric|min:1|max:1440', 'tips' => 'required|string|min:15', 'cooking' => [new Enum(CookingEnum::class)], 'range_id' => 'required|exists:ranges,id', 'status' => 'required|boolean' ]; return \array_merge( $rules, $this->pictureRules('picture', 1600, 900, 1600, 900, true), $this->pictureRules('picture_thumbnail', 430, 242, 430, 242, true), ); } /** * Get custom attributes for validator errors. * * @return array */ public function attributes(): array { return [ 'seo_title' => trans('title') . ' seo', 'seo_description' => trans('description') . ' seo', 'name' => trans('name'), 'slug' => trans('slug'), 'ingredients' => trans('ingredients'), 'ingredients.*.header' => trans('header in the list of ingredients'), 'ingredients.*.label' => trans('value of ingredients'), 'ingredients.*.value' => trans('value of ingredients'), 'teaser' => trans('teaser'), 'steps' => trans('steps'), 'difficulty' => trans('difficulty'), 'preparation' => trans('preparation'), 'duration' => trans('duration'), 'tips' => trans('tips'), 'cooking' => trans('cooking'), 'range_id' => trans('range'), 'status' => trans('publish') ]; } }