0

I know how to validate a query string with a single value in this way,

Validator::make($request->all(), [
    'category' => 'sometimes|nullable',
    'type' => [
        'required',
        Rule::in($this->propertyConfig['property_types']),
    ],
])->validate();

But what if I have a query string like this:

types=aa,bb,cc

I need to validate if aa, bb and cc are all in the array $types. How can I do that by using Laravel Validator?

1

2 Answers 2

1
$types = ['aa' , 'bb', 'cc'];
foreach($request->types as $type) {
    if(in_array($type, $types) {
        $flag = true;
    }
    else {
        $flag = false;
    }
}

Check flag variable after this code for your validation

Sign up to request clarification or add additional context in comments.

Comments

0
@php 
$ischeck = in_array($myvalue, explode(',', $myarray)) 
@endphp

2 Comments

I mean how to do this by using the Laravel validation framework.

Your Answer

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.