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

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -