public function __construct($message = '', $code = 0, \Exception $previous = null) { //Our message is actually a Validator if ($message instanceof Validator) { $this->validator = $message; $message = $this->validator->messages()->first(); } parent::__construct($message, $code, $previous); }
/** * 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; }
/** * All ...OrArray validation functions can use their non-array error message counterparts * * @param mixed $attribute The value under validation * @param string $rule Validation rule */ protected function getMessage($attribute, $rule) { if (substr($rule, -7) === 'OrArray') { $rule = substr($rule, 0, -7); } return parent::getMessage($attribute, $rule); }
public function getErrors() { if (!$this->validator) { throw new NoValidatorInstantiatedException(); } return $this->validator->errors(); }
/** * @param $data * @param $rules * @return \Illuminate\Validation\Validator */ function validate($data, $rules) { $validator = new \Illuminate\Validation\Validator(app('i18n'), $data, $rules); $validator->setPresenceVerifier(new \Illuminate\Validation\DatabasePresenceVerifier(capsule()->getDatabaseManager())); return $validator; }
/** * 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(); }
public function __construct(Translator $translator, $data, $rules, $messages = array()) { $messages = \Lang::get('Recaptcha::validation.recaptcha'); parent::__construct($translator, $data, $rules, $messages); }