Esempio n. 1
0
 /**
  * Perform validation on the model instance.
  *
  * @param   array   $rules     Validation rules to apply.
  * @param   array   $messages  Validation errors to display.
  *
  * @return  boolean
  */
 public function validate(array $rules = array(), array $messages = array())
 {
     // Use the rules applied statically to the model as fallback
     if (empty($rules)) {
         $rules = static::$rules;
     }
     // Nothing to validate, return early
     if (empty($rules)) {
         return true;
     }
     // Use the messages applied statically to the model as fallback
     if (empty($messages)) {
         $messages = static::$messages;
     }
     // Perform model validation
     $validator = new Validator($this->data(), $rules, $messages);
     if ($validator->fails()) {
         $this->errors()->merge($validator->errors());
         return false;
     }
     return true;
 }
Esempio n. 2
0
 /**
  * Determine if the user provides valid values for all fields.
  *
  * @return  boolean
  */
 public function validate()
 {
     $rules = $this->rules();
     $values = $this->data;
     $validator = new Validator($values, $rules);
     if ($validator->fails()) {
         $this->messages->merge($validator->errors());
         return false;
     }
     return true;
 }