php - validation value having two possible types -
how validate request value when should string or array both valid?
'val' => 'bail|required|string' 'val' => 'bail|required|array'
what the validation expression?
i don't think there way achieve using validation rules out of box. need use custom validation rules achieve this:
in appserviceprovider
's boot
method, add in
public function boot() { validator::extend('string_or_array', function ($attribute, $value, $parameters, $validator) { return is_string($value) || is_array($value); }); }
then can start using it:
'val' => 'bail|required|string_or_array'
optionally can set custom validation error messages, or using custom validation class achieve it. check out doc link above more information.
Comments
Post a Comment