I have two checkbox fields tech and active that I want to be nullable but I also want the values that can be entered to be restricted to a single value for one field and one of two values for the other field.
I came across the answer stackoverflow but I don't seem to implement it properly. Heres my code:
$validator = Validator::make($request->all(), [
'name' => 'required|string|max:150',
'email' => 'required|string|max:200',
'phone' => 'required|digits:11',
'branch' => 'required|string',
'department' => 'required|string',
'tech' => ['nullable','digits:1', Rule::in([1, 2])],
'role' => 'required|string',
'active' => ['nullable', 'string', 'max:6', Rule::in(['active'])]
]);
If I do this:
'tech' => 'nullable|digits:1',
'active' => 'nullable|string|max:6'
It works, but I need to validate the values that these fields can allow.
'tech' => 'nullable|digits:1|in:1,2', 'active' => 'nullable|string|max:6|in:active'and it is working just fine.['nullable', 'string', 'max:6', Rule::in(['active'])]instead. Let me implement yoursdd($request->all())gives you? Or maybedd($request->tech).