Skip to content

Commit

Permalink
Merge pull request #2316 from jim-parry/docs/model
Browse files Browse the repository at this point in the history
Add getValidationRules() to model UG page
  • Loading branch information
jim-parry authored Oct 10, 2019
2 parents a63b6fa + d192b98 commit 63defd5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions user_guide_src/source/models/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,28 @@ and simply set ``$validationRules`` to the name of the validation rule group you
protected $validationRules = 'users';
}

Retrieving Validation Rules
---------------------------

You can retrieve a model's validation rules by accessing its ``validationRules``
property::

$rules = $model->validationRules;

You can also retrieve just a subset of those rules by calling the accessor
method directly, with options::

$rules = $model->getValidationRules($options);

The ``$options`` parameter is an associative array with one element,
whose key is either "except" or "only", and which has as its
value an array of fieldnames of interest.::

// get the rules for all but the "username" field
$rules = $model->getValidationRules(['except' => ['username']]);
// get the rules for only the "city" and "state" fields
$rules = $model->getValidationRules(['only' => ['city', 'state']]);

Validation Placeholders
-----------------------

Expand Down

0 comments on commit 63defd5

Please sign in to comment.