作者:Tisho8
项目:conferenc
protected function formatErrors(Validator $validator)
{
if (count($validator->errors()->getMessages()) > 8) {
return [trans('messages.many-errors')];
}
return $validator->errors()->all();
}
作者:natalieduon
项目:konnectio
public function formatErrors(Validator $validator)
{
$repeatedAttendee = false;
$emptyNames = false;
$errors = $validator->errors()->all();
foreach ($errors as $index => $error) {
if (fnmatch('The selected user id.* is invalid.', $error)) {
// Removes from array; can still iterate through array with foreach
unset($errors[$index]);
$repeatedAttendee = true;
} else {
if (fnmatch('The name.* field is required.', $error)) {
unset($errors[$index]);
$emptyNames = true;
}
}
}
// Pushes more descriptive error message onto array
if ($repeatedAttendee) {
array_push($errors, 'The same attendee has been entered in the attendance list more than once.');
}
if ($emptyNames) {
array_push($errors, 'One of the names of the listed attendees has not been provided.');
}
return $errors;
}
作者:vitos868
项目:0e
public function formatErrors(Validator $validator)
{
foreach ($validator->errors()->all() as $error) {
Notifications::add($error, 'danger');
}
return $validator->errors()->getMessages();
}
作者:ding
项目:ap
/**
* Handle a failed validation attempt.
*
* @param \Illuminate\Contracts\Validation\Validator $validator
*
* @return void
*/
protected function failedValidation(Validator $validator)
{
if ($this->container['request'] instanceof Request) {
throw new ValidationHttpException($validator->errors());
}
parent::failedValidation($validator);
}
作者:CupOfTea69
项目:CardsAgainstTe
/**
* 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, $validation);
}
}
作者:jenk
项目:laravel-api-starte
/**
* Handle a failed validation attempt.
*
* @param \Illuminate\Contracts\Validation\Validator $validator
*
* @return mixed
*/
protected function failedValidation(Validator $validator)
{
if ($this->container['request'] instanceof BaseRequest) {
throw new ApiValidationException($validator->errors(), $this->getFailedValidationMessage($this->container['request']));
}
parent::failedValidation($validator);
}
作者:summer1112
项目:Laravel-Phon
/**
* Validates a phone number.
*
* @param string $attribute
* @param mixed $value
* @param array $parameters
* @param \Illuminate\Contracts\Validation\Validator $validator
* @return bool
* @throws \Propaganistas\LaravelPhone\Exceptions\InvalidParameterException
* @throws \Propaganistas\LaravelPhone\Exceptions\NoValidCountryFoundException
*/
public function validatePhone($attribute, $value, array $parameters, Validator $validator)
{
$this->attribute = $attribute;
$this->data = $validator->getData();
$this->parameters = array_map('strtoupper', $parameters);
$this->determineCountries();
$this->determineTypes();
$this->checkLeftoverParameters();
$phoneUtil = PhoneNumberUtil::getInstance();
// Perform validation.
foreach ($this->allowedCountries as $country) {
try {
// For default countries or country field, the following throws NumberParseException if
// not parsed correctly against the supplied country.
// For automatic detection: tries to discover the country code using from the number itself.
$phoneProto = $phoneUtil->parse($value, $country);
// For automatic detection, the number should have a country code.
// Check if type is allowed.
if ($phoneProto->hasCountryCode() && empty($this->allowedTypes) || in_array($phoneUtil->getNumberType($phoneProto), $this->allowedTypes)) {
// Automatic detection:
if ($country == 'ZZ') {
// Validate if the international phone number is valid for its contained country.
return $phoneUtil->isValidNumber($phoneProto);
}
// Force validation of number against the specified country.
return $phoneUtil->isValidNumberForRegion($phoneProto, $country);
}
} catch (NumberParseException $e) {
// Proceed to default validation error.
}
}
return false;
}
作者:gdgfo
项目:codelab-todo-ap
/**
* Get the response for a error validate.
*
* @param Validator $validator
* @return \Illuminate\Http\Response
*/
public function failedValidationResponse(Validator $validator)
{
if ($this->is('api/*')) {
return \ResponseFractal::respondErrorWrongArgs($validator->errors());
}
return $this->response($this->formatErrors($validator));
}
作者:josme
项目:bue
protected function formatErrors(Validator $validator)
{
$errors = $this->parseErrorRest($validator->errors()->getMessages());
$response = new ResponseWService();
$response->setDataResponse(ResponseWService::HEADER_HTTP_RESPONSE_SOLICITUD_INCORRECTA, array(), $errors, 'Datos Invalidos del formulario');
$response->response();
// return $validator->errors()->all();
}
作者:vainprojec
项目:vain-blo
protected function failedValidation(Validator $validator)
{
if ($this->ajax()) {
$this->session()->flashInput($this->all());
$this->session()->flash('errors', $validator->getMessageBag());
}
parent::failedValidation($validator);
}
作者:muhammadshakee
项目:laravel-api-boilerplate-oaut
public function throwStoreResourceFailedException($message = 'Failed to store your requested resource.', Validator $validator = null)
{
if ($validator instanceof Validator) {
throw new \Dingo\Api\Exception\StoreResourceFailedException($message, $validator->errors());
} else {
throw new \Dingo\Api\Exception\StoreResourceFailedException($message);
}
}
作者:system3
项目:consultas-tecnica
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Validator $validator, Request $request)
{
$messages = $validator->errors();
$request->session()->flash('status', 'Task was successful!');
foreach ($messages->all() as $message) {
print_r($message);
}
exit;
}
作者:quetzy
项目:contro
/**
* Extend update validations.
*
* @param \Illuminate\Contracts\Validation\Validator $validator
*
* @return void
*/
protected function extendUpdate(ValidatorResolver $validator)
{
$name = Keyword::make($validator->getData()['name']);
$validator->after(function (ValidatorResolver $v) use($name) {
if ($this->isRoleNameGuest($name)) {
$v->errors()->add('name', trans('orchestra/control::response.roles.reserved-word'));
}
});
}
作者:bitlle
项目:nov
/**
* Format error messages for ajax requests
*
* @param Validator $validator
* @return array
* @internal param Request $request
*/
protected function formatErrors(Validator $validator)
{
$errors = $validator->errors()->all();
$error = '';
foreach ($errors as $errorMessage) {
$error = $errorMessage;
}
return ['success' => false, 'title' => trans('common.fail'), 'message' => $error];
}
作者:Aphix-Lab
项目:laravel-aphix-boilerplat
protected function formatValidationErrors(Validator $validator)
{
foreach ($validator->errors()->getMessages() as $key => $message) {
if (starts_with($key, 'roles')) {
$validator->errors()->add('roles', $message[0]);
}
}
return $validator->errors()->getMessages();
}
作者:bitlle
项目:nov
/**
* @param Validator $validator
* @return array
*/
protected function formatErrors(Validator $validator)
{
$messages = $validator->errors();
$errors = [];
foreach ($this->fields as $field) {
if (!$messages->has($field)) {
continue;
}
$errors[$field] = $messages->first($field);
}
return $errors;
}
作者:bitlle
项目:nov
/**
* @param Validator $validator
* @return array
*/
protected function formatErrors(Validator $validator)
{
$messages = $validator->errors();
$fields = ['email', 'password', 'password_confirmation', 'token'];
$errors = [];
foreach ($fields as $field) {
if (!$messages->has($field)) {
continue;
}
$errors[$field] = $messages->first($field);
}
return $errors;
}
作者:bitlle
项目:nov
/**
* @param Validator $validator
* @return array
*/
protected function formatErrors(Validator $validator)
{
$messages = $validator->errors();
$fields = ['product_code', 'product_price', 'product_page', 'product_discount', 'product_quantity'];
$errors = [];
foreach ($fields as $field) {
if (!$messages->has($field)) {
continue;
}
$errors[$field] = $messages->first($field);
}
return $errors;
}
作者:bitlle
项目:nov
/**
* @param Validator $validator
* @return array
*/
protected function formatErrors(Validator $validator)
{
$messages = $validator->errors();
$fields = ['question_category_id', 'question_content', 'question_title'];
$errors = [];
foreach ($fields as $field) {
if (!$messages->has($field)) {
continue;
}
$errors[$field] = $messages->first($field);
}
return $errors;
}
作者:stevebauma
项目:ithu
/**
* Formats the validators errors to allow any number of security questions.
*
* @param Validator $validator
*
* @return array
*/
protected function formatErrors(Validator $validator)
{
$errors = $validator->getMessageBag()->toArray();
$processed = [];
foreach ($errors as $key => $error) {
$parts = explode('.', $key);
// If we have exactly two parts, we can work with the error message.
if (count($parts) === 2) {
list($name, $key) = $parts;
$field = sprintf('%s[%s]', $name, $key);
$processed[$field] = $error;
}
}
return $processed;
}