Laravel Validation: Validating OR instead of AND

user742736

I am trying to validation a field to see if the value is an integer OR an array. The rule below check if the value is an integer AND array.

'field' => "integer|array",
Marwelln

If you want to use OR you will need to create a custom validation rule.

'field' => 'integer_or_array'

Validator::extend('integer_or_array', function($attribute, $value){
    return is_int($value) || is_array($value);
});

Validator::extend('integer_or_array', function($attribute, $value){
    return is_int($value) || is_array($value);
});
$validator = Validator::make(Input::all(), ['field' => 'integer_or_array']);
if ($validator->fails()) {
    // do something here
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Related Related

HotTag

Archive