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 numeric. A rule like maximum: 9000 will be valid, but if it is provided, then it should be a number less than 9000.

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:

  public function setumber attribute ($ value) {if ($ value! == blank & number_number ($ value)) {$ this-> Attributes ['number'] = (int) $ value; }}   



Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -