check()) { $this->merge([ 'slug' => Str::slug($this->title), 'status' => $this->status === null ? 0 : 1, 'notification' => $this->notification === null ? 0 : 1, ]); if ($this->type == ArticleCategory::sondage()) { $this->merge([ 'multiple_response' => $this->multiple_response === null ? 0 : 1, 'stop_poll' => $this->stop_poll === null ? 0 : 1, ]); } return true; } return false; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { $moreRules = []; if ($this->type == ArticleCategory::sondage()) { $moreRules = [ 'question' => 'required|min:10,max:255', 'answers' => 'required|array', 'answers.*' => 'required|string|distinct|min:10,max:255', 'multiple_response' => 'required|boolean', 'stop_poll' => 'required|boolean', ]; } return array_merge([ 'title' => 'required|min:10|max:255', 'slug' => 'required|unique:articles,slug|max:255', 'content' => 'required|min: 20', 'status' => 'required|boolean', 'notification' => 'required|boolean', 'type' => [ 'required', // @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed function ($attribute, $value, $fail) { if (!in_array($value, ArticleCategory::toValues())) { $fail(__('Veuillez choisir entre :values', [ 'value' => implode(',', ArticleCategory::toLabels()) ])); } } ] ], $moreRules); } }