merge([ 'flagship_product' => empty($this->flagship_product) ? null : $this->flagship_product ]); return parent::authorize(); } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return \array_merge(parent::rules(), [ 'slug' => [ 'required', //phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed function ($attribute, $value, $fail) { if ($this->range->slug !== $value and Range::where('slug', $value)->exists()) { $fail("Le champ Nom est déjà utilisé"); } } ], 'picture' => 'sometimes|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=640,height=564', 'picture_r' => 'sometimes|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=1366,height=563', 'status' => 'required|boolean', 'flagship_product' => [ 'nullable', 'exists:products,id', // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed function ($attribute, $value, $fail) { if (!Products::where('range_id', $value)->get()) { $fail('Le product sélectionné n\'appartient pas à cette gamme'); } } ], 'subranges' => 'sometimes|array|max:5', 'subranges.*' => 'int|exists:sub_ranges,id', ]); } }