Slide 29
Slide 29 text
public function rules(): array
{
return [
'info_type' => ['required', 'in:mail,sms,postcard'],
'mail' => match ($this->input('info_type')) {
'mail' => ['required', 'email'],
'default' => ['nullable', 'email']
},
'tel' => match ($this->input('info_type')) {
'sms' => ['required', 'regex:/\A0\d{9,10}\z/'],
'default' => ['nullable', 'regex:/\A0\d{9,10}\z/']
},
'address' => match ($this->input('info_type')) {
'postcard' => ['required', 'string', 'max:255'],
'default' => ['nullable', 'string', 'max:255']
},
];
}