Laravel 5中是否有一个内置的验证器可以检查值是否在我列入白名单的值的数组中。有点像:
$rules = [
'field_name' => "required|in_array('yes', 'no', 'maybe')",
];
答案 0 :(得分:16)
有in
from itertools import dropwhile as dw, takewhile as tw
data=['red' '1', 'blue' '8', 'green' '2', 'orange' '6']
data = sorted((("".join(dw(str.isalpha,s)), "".join(tw(str.isalpha,s)))
for s in data),key=lambda x: int(x[0]),reverse=True)
print(data)
[('8', 'blue'), ('6', 'orange'), ('2', 'green'), ('1', 'red')]
答案 1 :(得分:0)
Laravel 5.7
use Illuminate\Validation\Rule;
Validator::make($data, [
'field_name' => [
'required',
Rule::in(['yes', 'no', 'maybe']),
],
]);