Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Is there a built in validator in Laravel 5 that checks if value is in array of my whitelisted values sort of speak.. Something like:
$rules = [ 'field_name' => "required|in_array('yes', 'no', 'maybe')", ];
There's in
in
$rules = [ 'field_name' => "required|in:yes,no,maybe", ];
Add a comment
Laravel 5.7
use Illuminate\Validation\Rule; Validator::make($data, [ 'field_name' => [ 'required', Rule::in(['yes', 'no', 'maybe']), ], ]);
In addition to this one, I needed a validation if filed_name starts with one of the items from the array, so you can use starts_with in the same manner
filed_name
starts_with
$rules = [ 'field_name' => "required|starts_with:foo,bar", ];
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.