I
I
Ivan Huk2020-08-29 11:56:11
Laravel
Ivan Huk, 2020-08-29 11:56:11

Why doesn't required_unless work with boolean?

There is a piece of code:

$validator = Validator::make($args, array(
            'name' => 'required|min:4',
            'phone' => 'required|numeric|digits_between:3,15',
            'delivery' => 'required|boolean',
            'address' => 'required_unless:delivery,false|min:10|max:60',
        ));


If you send parameters
delivery: false
address: "test"
then the error The address must be at least 10 characters , i.e. the validator skips
required_unless:delivery

, I understand that in required_unless:delivery,false false acts as a string, and in the parameter I send a boolean type.

How can this be bypassed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2020-08-29
@alexey-m-ukolov

delivery: 0
'required_unless:delivery,0'

J
jazzus, 2020-08-29
@jazzus

'address' => [
   // $this если в реквест файле или $request
   Rule::requiredIf($this->delivery),
  'min:10'
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question