I am trying to validate a form request and I want to accept the field say test if only it has a value or ABC or XYZ. How can I achieve this?
I currently have
$request->validate([
'test' => 'required|unique:tests',
]);
I am trying to validate a form request and I want to accept the field say test if only it has a value or ABC or XYZ. How can I achieve this?
I currently have
$request->validate([
'test' => 'required|unique:tests',
]);
The Laravel docs are quite helpful when it comes to these issues.
Laravel Docs - Validation - Available Methods
Laravel Docs - Validation - Rule - in
'test' => [
'required',
Rule::in(['ABC', 'XYZ']),
]
or
'test' => 'required|in:ABC,XYZ',
You can use regular expression to validate this field
your regular expression for ABC OR XYZ
Code is
$request->validate([
'test' => 'required|unique:tests|regex:/ABC|XYZ/g',
]);