jeudi 19 janvier 2017

Laravel validation: value has to be in array only if field is required

I am using Laravel 5.3 and I need to validate a field

The field I need to validate is only required if another field has the value 1 and this works.

If the field is required, the value entered must be in a given array.

The problem is the value being validated is NULL so doesn't appear in the array and validation fails

Here is my rule so far

$test->other_field = 0
$test->my_field = NULL;

$rules = array(
    'my_field' => 'required_if:other_field,1', //|in:' . implode(',', $array),
);

The required_if works fine but if i uncomment the in part, the validation fails



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2iERRDb
via IFTTT

Aucun commentaire:

Enregistrer un commentaire