文档方式
$values = ['one', 'two', 'three'];
\Validator::make($input, ['value' => 'in:one,two,three']);
我可以用数组设置选项吗?现在我这样用,我不喜欢
\Validator::make($input, ['value' => 'in:' . implode(',', $values)]);
文档方式
$values = ['one', 'two', 'three'];
\Validator::make($input, ['value' => 'in:one,two,three']);
我可以用数组设置选项吗?现在我这样用,我不喜欢
\Validator::make($input, ['value' => 'in:' . implode(',', $values)]);
I don't think there's another way than using implode
like you do now. Not even with a custom validation rule. The essential problem with a syntax like this
['value' => ['in' => $values]];
is that Laravel just ignores the 'in'
key and thinks $values
are a set of validation rules.
Is there a reason why using implode
is a problem? (other than you don't liking it)