Laravel Validation required this or that

I need to validate a request account_type if it is either ‘Personal’ or ‘Organizational’
So that i can validate other field by required if account_type,personal.Heres the code that i have tried.

        'account_type' => 'required|options:PERSONAL,ORGANIZATIONAL',
        'per_client_name' => 'required_if:account_type,PERSONAL|string',
        'per_street' => 'required_if:account_type,PERSONAL',
        'per_address' => 'required_if:account_type,PERSONAL',
        'org_name' => 'required_if:account_type,ORGANIZATIONAL',
        'org_type' => 'required_if:account_type,ORGANIZATIONAL',
        'org_cont_name' => 'required_if:account_type,ORGANIZATIONAL'

Method IlluminateValidationValidator::validateOptions does not exist. This is the error that i got.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

if you only have these 2 options (PERSONAL,ORGANIZATIONAL), then use in instead of options. Like this :

'account_type' => 'required|in:PERSONAL,ORGANIZATIONAL',

It works for me.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x