/**
  * Returns validation errors, if any
  *
  * @return MessageBag
  */
 public function messages()
 {
     if (is_null($this->validator)) {
         $this->validate();
     }
     if (!$this->validator->fails()) {
         return App::make(MessageBag::class);
     }
     return $this->validator->messages();
 }
Exemplo n.º 2
0
 /**
  * Returns validation errors, if any
  *
  * @return \Illuminate\Contracts\Support\MessageBag
  */
 public function messages()
 {
     if (is_null($this->validator)) {
         $this->validate();
     }
     if (!$this->validator->fails()) {
         return app('\\Illuminate\\Support\\Messagebag');
     }
     return $this->validator->messages();
 }
 public function validate()
 {
     if ($this->validator->fails()) {
         $messages = [];
         foreach ($this->validator->messages()->all("The :key variable is not defined or invalid") as $var => $message) {
             $messages[] = $message;
         }
         $msg = 'The .env file has some problems. Please check config/laravel-env-validator.php' . PHP_EOL . implode(PHP_EOL, $messages);
         throw new Exception($msg);
     }
 }
Exemplo n.º 4
0
 /**
  * Validate the data given with some optional rules and messages
  *
  * @param array $data
  * @param null $rules
  * @param array $messages
  * @param array $customAttributes
  * @return Validator|\Illuminate\Validation\Validator
  * @throws ValidationException
  */
 public function validate(array $data, $rules = null, array $messages = [], array $customAttributes = [])
 {
     $rules = $rules ?: $this->getRules();
     $messages = empty($messages) ? $this->messages : $messages;
     $customAttributes = empty($customAttributes) ? $this->customAttributes : $customAttributes;
     $this->validated = $this->validatorFactory->make($data, $rules, $messages, $customAttributes);
     if ($this->exceptionStatus) {
         if ($this->validated->fails()) {
             $e = new ValidationException($this->getFailMessage(), static::$statusCode, static::EXCEPTION_KEY);
             $e->setErrors($this->validated->messages());
             throw $e;
         }
     }
     return $this->validated;
 }
Exemplo n.º 5
0
 /**
  * @param array $data
  * @param array $rules
  * @param array $messages
  * @param array $customAttributes
  *
  * @return Validator|\Illuminate\Validation\Validator
  * @throw StoreResourceFailedException
  */
 public function validate(array $data, array $rules = [], array $messages = [], array $customAttributes = [])
 {
     if ($this->getScenario() !== null) {
         $scenarioRules = camel_case($this->getScenario() . 'Rules');
         if ($this->{$scenarioRules} !== null) {
             $rules = empty($rules) ? $this->{$scenarioRules} : array_merge($rules, $this->{$scenarioRules});
         }
     } else {
         $rules = empty($rules) ? $this->rules : array_merge($rules, $this->rules);
     }
     $messages = empty($messages) ? $this->messages : array_merge($messages, $this->messages);
     $customAttributes = empty($customAttributes) ? $this->customAttributes : array_merge($customAttributes, $this->customAttributes);
     $this->validated = $this->validatorFactory->make($data, $rules, $messages, $customAttributes);
     if ($this->validated->fails()) {
         throw new StoreResourceFailedException(trans('messages.validation_failed'), $this->validated->messages());
     }
     return $this->validated;
 }
Exemplo n.º 6
0
 /**
  * Handle a failed validation attempt.
  *
  * @param $validator
  *
  * @return mixed
  */
 protected function failedValidation(Validator $validator)
 {
     return response()->json($validator->messages(), 400);
 }