Validation
Last updated
Last updated
Lift provides three attributes to help you validate your model's public properties.
โ ๏ธ The rules will be validated only when you save your model (create or update)
The Rules
attribute allows you to set your model's public properties validation rules the same way as you would do with the rules
function on a FormRequest
, but you can set it directly on your public properties.
You can also pass a second parameter to the Rules
attribute to set a custom error message for the validation rule.
The validation messages work with localization, so you can set your messages ina lang
file and under the hood, Lift will use the __()
helper to get the message.
โ ๏ธ The rules will be validated only when you create your model
The CreateRules
attribute works the same way as the Rules
attribute, but the rules will be validated only when you create your model.
In the example below the name
property will be validated with the set rules for both when creating and updating the model. The email
and password
properties will be validated only when creating the model.
โ ๏ธ The rules will be validated only when you update your model
The UpdateRules
attribute works the same way as the Rules
attribute, but the rules will be validated only when you update your model.
In the example below the name
property will be validated with the set rules for both when creating and updating the model. The email
and password
properties will be validated only when updating the model.
You can also mix the three validation attributes to set different rules for creating and updating your model.