check(); } /** * Prepare the data for validation. */ protected function prepareForValidation(): void { $this->merge([ 'news_club_id' => intval($this->news_club->getKey()), 'answers' => collect($this->answers)->map(function ($value) { return intval($value); })->toArray(), ]); } /** * Get the validation rules that apply to the request. */ public function rules(): array { return [ 'news_club_id' => 'required|integer|exists:news_clubs,id', 'answers' => [ 'required', 'array', // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed function (string $attribute, $value, callable $fail) { if ( $this->news_club->type->equals(NewsClubTypeEnum::survey) && ! $this->news_club->multiple_answers && count($value) > 1 ) { $fail(trans('Une seule réponse est autorisée pour ce sondage')); } }, ], 'answers.*' => 'required|integer|exists:surveys_answers,id', ]; } /** * Get custom attributes for validator errors. */ public function attributes(): array { return [ 'news_club_id' => trans_choice('models.classes.news_club', 1), 'answers' => trans_choice('models.classes.surveys_answer', 1), ]; } }