|string> */ public function rules(): array { ToolboxHelper::validateRecaptcha($this, \config('services.google.recaptcha.version')); $typeContactForm = $this->input('enumType'); // Validation for common fields. $rules = [ 'enumType' => ['required', Rule::enum(ContactFormType::class)], 'lastname' => ['required', 'min:1', 'max:60'], 'firstname' => ['required', 'min:1', 'max:60'], 'message' => ['required', 'min:10', 'max:255'], 'email' => ['required', 'min:1', 'max:60', 'email:rfc,dns,spoof'], ]; // Validation for breeder enum. if (ContactFormType::breeder->equals(ContactFormType::make($typeContactForm))) { $rules = array_merge($rules, [ 'phone' => ['required', 'min:1', 'max:60'], 'typeelevage' => ['array', 'min:1'], 'typeelevage.*' => [Rule::enum(BreedType::class)], 'zonegeo' => ['array', 'min:1'], 'zonegeo.*' => [Rule::enum(Department::class)], ]); } // Validation for restauration enum. if (ContactFormType::restauration->equals(ContactFormType::make($typeContactForm))) { $rules = array_merge($rules, [ 'company' => 'string|max:255', ]); } // Add the country field. if ( ContactFormType::restauration->equals(ContactFormType::make($typeContactForm)) || ContactFormType::export->equals(ContactFormType::make($typeContactForm)) || ContactFormType::commitments->equals(ContactFormType::make($typeContactForm)) || ContactFormType::info->equals(ContactFormType::make($typeContactForm)) ) { $rules = array_merge($rules, [ 'country' => ['required', 'min:1', 'max:150'], ]); } // Add the optional phone field. if ( ContactFormType::restauration->equals(ContactFormType::make($typeContactForm)) || ContactFormType::export->equals(ContactFormType::make($typeContactForm)) || ContactFormType::finance->equals(ContactFormType::make($typeContactForm)) || ContactFormType::commitments->equals(ContactFormType::make($typeContactForm)) || ContactFormType::info->equals(ContactFormType::make($typeContactForm)) ) { $rules = array_merge($rules, [ 'phone' => ['max:60'], ]); } // Add the town and postalcode fields. if ( ContactFormType::restauration->equals(ContactFormType::make($typeContactForm)) || ContactFormType::export->equals(ContactFormType::make($typeContactForm)) || ContactFormType::finance->equals(ContactFormType::make($typeContactForm)) || ContactFormType::commitments->equals(ContactFormType::make($typeContactForm)) || ContactFormType::info->equals(ContactFormType::make($typeContactForm)) || ContactFormType::press->equals(ContactFormType::make($typeContactForm)) ) { $rules = array_merge($rules, [ 'town' => 'string|required|min:2|max:255', 'postalcode' => 'string|required|min:2|max:60', ]); } // Validation for restauration and export commun fields. if ( ContactFormType::restauration->equals(ContactFormType::make($typeContactForm)) ) { $rules = array_merge($rules, [ 'type' => ['array', 'min:1'], 'type.*' => [Rule::enum(CustomerAskingType::class)], ]); } if ( ContactFormType::export->equals(ContactFormType::make($typeContactForm)) ) { $rules = array_merge($rules, [ 'typeExport' => ['array', 'min:1'], 'typeExport.*' => [Rule::enum(ExportAskingType::class)], ]); } // Validation for press enum. if (ContactFormType::press->equals(ContactFormType::make($typeContactForm))) { $rules = array_merge($rules, [ 'subject' => ['required', Rule::enum(PressType::class)], 'company' => 'required|string|min:2|max:255', 'phone' => ['required', 'max:60'], 'newsletter' => 'boolean' ]); } return $rules; } }