如何在laravel中使用multi required_if?

1) I am new to laravel and want to integrate validation rules. My requirement is to make third field mandatory on basis of two other fields. Field C is required if both a and b are true. I have used required_if to put validation on basis of other single field but how can i use required_if to check two fields?

2) To achieve above functionality i tried custom validation rule as well. But it's working only if i will pull required rule alongwith.

For example:

'number_users' => 'required|custom_rule'   //working 
'number_users' => 'custom_rule'   //Not working

You can use conditional rules for that.

Here's a simple example:

$input = [
    'a' => true,
    'b' => true,
    'c' => ''
];

$rules = [
    'a' => 'required',
    'b' => 'required'
    // specify no rules for c, we'll do that below
];

$validator = Validator::make($input, $rules);

// now here's where the magic happens
$validator->sometimes('c', 'required', function($input){
    return ($input->a == true && $input->b == true);
});

dd($validator->passes()); // false in this case

Laravel evaluates each rule in the giver order. Let's say:

'number_users' => 'required|custom_a|custom_b'

custom_b rule will be evaluate when required and custom_b are true because these rules were already evaluated.

Take a look at the laravel validation docs which I pasted a link below, you can use required_if, required_without and others to suit your needs.

See the Laravel Validation Docs Here

Here is your answer

 'field3' => 'required_if:field_1 | required_if:field_2'