This fails:
Validator::make([
'whole_day' => true,
'time' => ''
], [
'time' => 'required_if:whole_day,false'
]);
Hey @GrahamCampbell can you please provide some information on the issue? Is it somehow an intended behavior?
Not sure. Have you tried with 1
or "true"
?
It seems to work with 'required_if:whole_day,0'
. Thanks. It should be documented though.
:)
Just had exactly the same problem, still not documented. Should definitely be either fix for documented.
+1 Thanks @pdcmoreira
It should be documented
Perhaps we can have such that required_if
looks for casts
to boolean
and then checks for true/false instead of just 1/0?
protected $casts = ['whole_day' => 'boolean'];
required_if:whole_day,true
.
A reason is the default validation message that appears:
The COLUMN_NAME field is required when whole day is true
definitely looks better than:
The COLUMN_NAME field is required when whole day is 1
.
any news?
It also just doesn't work if incoming value type is actual boolean.
It also just doesn't work if incoming value type is actual boolean.
My hack is, to refactor this line,
'citizen' => 'required|boolean',
to
'citizen' => 'required',
So, now, it will be available
'passport_number' => 'required_if:citizen,true',
'visa_type' => 'required_if:citizen,false',
Why is this closed? Either the implementation should be fixed, or the documentation should reflect this surprising (in an unwelcome sense) behavior.
Anyone's free to send in prs to the docs.
Most helpful comment
It seems to work with
'required_if:whole_day,0'
. Thanks. It should be documented though.