Laravel Validation - How to check if a value exists in a given array?

前端 未结 2 461
谎友^
谎友^ 2021-02-14 18:38

So, okay i tried a lot of rules from validation docs but all give me same error saying

Array to string conversion

Here is how I add

2条回答
  •  攒了一身酷
    2021-02-14 19:03

    Update: You are now able to use the Rule class instead of imploding values yourself as described in the correct answer. Simply do:

    ['someProperty' => ['required', Rule::in(['needed', 'stuff'])]];
    

    As mentioned in the 'validating arrays' section in the documentation: https://laravel.com/docs/5.6/validation#validating-arrays

提交回复
热议问题