Home > database >  required_if not case in Laravel
required_if not case in Laravel

Time:09-27

I have this validation:

 'target' => ['required', Rule::in(['ads', 'users',...])],
 'expires_at' => 'required_if:target,!=,ads',

I need to make expires_at is not required if the target is ads if the user chooses other options make expires_at required again!

CodePudding user response:

You can try required_unless.

 'expires_at' => 'required_unless:target,ads',

Here is the documentation for that rule.

  • Related