Level 75
What about like this?
'paymode_id' => $request->has('payment_date')
? 'required_unless:payment_date,null|exists:paymodes,id'
: 'required_unless:payment_date,null',
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
I have this form validation rule.
'paymode_id' => 'required_unless:payment_date,null|exists:paymodes,id',
The problem is that event if the payment date is null, it checks for an existing paymode id.
Is it possible to check if the paymode id exists only if the payment date is not null ?
Thanks for your help.
V
'paymode_id' => [
'required_unless:payment_date,null',
Rule::when($request->has('payment_date'), fn () => Rule::exists('paymodes')),
],
Please or to participate in this conversation.