@synchro it should be
'otp' => ['nullable', 'required_without:qrid', new OTP(), 'exists:otps,otp'],
'qrid' => ['nullable', 'required_without:otp', new QrId(), 'exists:otps,qrid'],
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm trying to validate a request that must provide at least one of otp and qrid fields. I'm using required_without to enforce that, but I'm not clear on how it interacts with sometimes and nullable and my custom validators:
'otp' => ['required_without:qrid', 'sometimes', 'nullable', new OTP(), 'exists:otps,otp'],
'qrid' => ['required_without:otp', 'sometimes', 'nullable', new QrId(), 'exists:otps,qrid'],
if either of these are missing or null, I get an error from my custom validator, which does not allow null values – but as far as I can I can see, the validation should have been allowed to pass before it gets to that point. Do I need these rules in a different order or something? Or is there a "stop validating if null" rule?
I don't really want to allow null at all, I've just seen it recommended for "at least one of" situations like this, and this.
Please or to participate in this conversation.