/** * 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(); }
/** * 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); } }
/** * Does validation fails with given data * * @return bool * @throws \Exception */ public function fails() { if (is_null($this->validated)) { throw new \Exception("No data has been validated yet"); } return $this->validated->fails(); }
/** * Check if the form is valid * * @return bool */ public function isValid() { if (!$this->validator) { $this->validate(); } return !$this->validator->fails(); }
/** * Run the validation routine against the given validator. * * @param \Illuminate\Contracts\Validation\Validator $validator * @param \Illuminate\Http\Request|null $request * @return void */ public function validateWith($validator, Request $request = null) { $request = $request ?: app('request'); if ($validator->fails()) { $this->throwValidationException($request, $validator); } }