Beispiel #1
0
 /**
  * Validate the model's attributes.
  *
  * @param  array  $rules
  * @return bool
  */
 public function validate(array $rules = array())
 {
     $rules = $this->processRules($rules ?: static::$rules);
     $this->validator = $this->validatorFactory->make($this->attributes, $rules);
     if ($this->validator->fails()) {
         $this->errors = $this->validator->errors();
         return false;
     }
     $this->errors = null;
     return true;
 }
Beispiel #2
0
 public function getErrors()
 {
     if (!$this->validator) {
         throw new NoValidatorInstantiatedException();
     }
     return $this->validator->errors();
 }
Beispiel #3
0
 /**
  * Pass the validator and it will build the response with the error messages
  * @param Illuminate\Validation\Validator $validator
  * @return Illuminate\Support\Facades\Response
  */
 public function validationError($validator)
 {
     $messages = $validator->errors()->getMessages();
     $this->response = $this->laravelResponse->setContent(json_encode(['ErrorCode' => 'ValidationFail', 'ErrorDescription' => 'The input validation failed', 'errors' => $messages]))->setStatusCode(400);
     return $this->respond();
 }