When a user fill Message (textarea) he/she can't fill Date,Time,Venue values.
Those three fields will consider only when Message is empty and all those three fields are filled.
How to do this using Laravel form validation? Is it possible to define these logic in Request's rule method?
I am new for Laravel.
Thanks in advance
You can achieve this (serverside) by using conditional validation rules:
I would say for your case:
Chain rules if you need by separating them with pipe
Follows an example snippet. Use this method inside your ExampleFormRequest extending Request
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$rules = [];
switch ($this->method()) {
case 'PATCH':
case 'PUT':
case 'POST':
$rules = [
'date' => 'required_without:message',
'time' => 'required_without:message',
'venue' => 'required_without:message',
'message' => 'required_without_all:date,time,venue',
];
break;
default:
// Perform no alteration to rules
break;
}
return $rules;
}
Checkout documentation here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With