Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

makapaka's avatar

Validation rules to check for allowed values

I'm sorry I'm sure something like this is done before, I'm just not sure I've found a clean solution. I want to use validation rules to check for actual allowed values in the request body:

$allowedValues = ['blah1', 'blah2', 'blah3'];

$rules = [
    'type' => `must be any of $allowedValues`
];

Is there a laravely way to do this, or do I need a custom function to loop through the values and return boolean valid or not ?

thanks

0 likes
1 reply
makapaka's avatar
makapaka
OP
Best Answer
Level 7

Found it just after I posted :)

'type' => Rule::in($allowedTypes)
1 like

Please or to participate in this conversation.