欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Laravel Validation check array size min and max between

I just need to check in Laravel validation that an array contains minimum 2 values and maximum 4 values. Is there any default validation rule can be used for this ? The size element checks for exact size match and the other rules likes min and max are for strings, digits and file size.

shareimprove this questionedited Feb 20 '17 at 10:50asked Feb 20 '17 at 10:43Happy Coder1,04412063

   I do not believe there currently is a validation rule for this. You can however create a custom validation rule. – Jerodev Feb 20 '17 at 10:51   which laravel version do you use? – darthsoup Feb 20 '17 at 10:52   I am using Laravel 5.2 – Happy Coder Feb 20 '17 at 10:54   Ah Ok. You need to make your own validator check. The default size validator only checks the value and not min/max. – darthsoup Feb 20 '17 at 11:00

You can use between. . https://laravel.com/docs/5.2/validation#rule-between

For example:

'users' => 'required|array|between:2,4'

It is not explicitly stated in the docs, but it works with arrays, just like size.

shareimprove this answeranswered Feb 20 '17 at 11:21piscator1,7312417

来自  https://stackoverflow.com/questions/42342411/laravel-validation-check-array-size-min-and-max


普通分类: