3

Documentation way

$values = ['one', 'two', 'three'];
\Validator::make($input, ['value' => 'in:one,two,three']);

Can I set in options with array? Now I use it like that, and I don't like it

\Validator::make($input, ['value' => 'in:' . implode(',', $values)]);
asked Feb 19, 2015 at 16:34
2
  • did you try ['value' => ['in' => $values]]; ? Commented Feb 19, 2015 at 16:48
  • yes, Method [validateEasy] does not exist. Commented Feb 19, 2015 at 17:09

1 Answer 1

0

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)

answered Feb 19, 2015 at 21:17
Sign up to request clarification or add additional context in comments.

1 Comment

One problem could be values containing ,.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.