php - Laravel4 Validator and nullable fields -
I have a question about Laravel 4 and validation concept.
I have my mysql table and my models are Calass .. We can assume that we have a field blank ...
If this field is not empty then how do I Can i validate (For example, I will have an integer value of my maximum value & lt;)
The 'required' rule, Verification will always control the field as an alternative, if the rule is zero or empty string, then To prevent the empty or empty string from being saved in the database (MySQL will convert it to 0 for the integer field), you can set a mutator for the attribute. In your model: numeric. A rule like maximum: 9000 will be valid, but if it is provided, then it should be a number less than 9000.
public function setumber attribute ($ value) {if ($ value! == blank & number_number ($ value)) {$ this-> Attributes ['number'] = (int) $ value; }}
Comments
Post a Comment