0

Say a model has a status property, that holds an array of strings. If this array contains a string name "Other", the status_other field should be required. I can achieve this with the following rules:

'status' => 'nullable|array',
'status_other' => Rule::requiredIf(in_array('Other', $this->model->status))

Is there a way to write the status_other rule as a string? I tried:

'status_other' => 'required_if:status,in:Other',

and

'status_other' => 'required_if:status,Other',

Both that did not work.

1
  • Something like that could help. Commented Aug 24, 2021 at 20:34

1 Answer 1

1

You can compare it by using '==' to match the string in the array.

'status_other' => 'required_if:status,==,Other',
Sign up to request clarification or add additional context in comments.

1 Comment

How does == check if "Other" is inside "status" array? Just tried your suggestion without success.

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.