|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))) { $breeder = [ 'phone' => ['required', 'min:1', 'max:60'], 'typeelevage' => ['array', 'min:1'], 'typeelevage.*' => [Rule::enum(BreedType::class)], 'zonegeo' => ['array', 'min:1'], 'zonegeo.*' => [Rule::enum(Department::class)], ]; $rules = array_merge($rules, $breeder); } /** Validation for restauration enum */ if (ContactFormType::restauration->equals(ContactFormType::make($typeContactForm))) { $restauration = [ 'company' => 'string|max:255', ]; $rules = array_merge($rules, $restauration); } /** 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)) ) { $addCountry = [ 'country' => ['required', 'min:1', 'max:150'], ]; $rules = array_merge($rules, $addCountry); } /** 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)) ) { $addNoRequiredPhone = [ 'phone' => ['max:60'], ]; $rules = array_merge($rules, $addNoRequiredPhone); } /** 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)) ) { $addTownAndPostalCodeFields = [ 'town' => 'string|required|min:2|max:255', 'postalcode' => 'string|required|min:2|max:60', ]; $rules = array_merge($rules, $addTownAndPostalCodeFields); } /** Validation for restauration and export commun fields */ if ( ContactFormType::restauration->equals(ContactFormType::make($typeContactForm)) || ContactFormType::export->equals(ContactFormType::make($typeContactForm)) ) { $restaurationExport = [ 'type' => ['array', 'min:1'], 'type.*' => [Rule::enum(CustomerAskingType::class)], ]; $rules = array_merge($rules, $restaurationExport); } /** Validation for press enum */ if (ContactFormType::press->equals(ContactFormType::make($typeContactForm))) { $press = [ 'subject' => ['required', Rule::enum(PressType::class)], 'company' => 'required|string|min:2|max:255', 'phone' => ['required', 'max:60'], 'newsletter' => 'boolean' ]; $rules = array_merge($rules, $press); } return $rules; } }