Skip to content

Commit

Permalink
Document for Rule::requireIf
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuan Pham committed Feb 21, 2019
1 parent 1fe9800 commit 3de23f8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,20 @@ The field under validation must be present in the input data and not empty. A fi

The field under validation must be present and not empty if the _anotherfield_ field is equal to any _value_.

If you want to require the field with a custom condition, you can use the `Rule::requiredIf` method to construct the rule:

use Illuminate\Validation\Rule;

Validator::make($request->all(), [
'role_id' => Rule::requiredIf($request->user()->is_admin),
]);

Validator::make($request->all(), [
'role_id' => Rule::requiredIf(function () use ($request) {
return $request->user()->is_admin && $some_other_complicated_condition;
}),
]);

<a name="rule-required-unless"></a>
#### required_unless:_anotherfield_,_value_,...

Expand Down

0 comments on commit 3de23f8

Please sign in to comment.