本文整理汇总了PHP中Illuminate\Contracts\Validation\Validator::errors方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::errors方法的具体用法?PHP Validator::errors怎么用?PHP Validator::errors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Contracts\Validation\Validator
的用法示例。
在下文中一共展示了Validator::errors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: formatErrors
protected function formatErrors(Validator $validator)
{
if (count($validator->errors()->getMessages()) > 8) {
return [trans('messages.many-errors')];
}
return $validator->errors()->all();
}
示例2: formatErrors
public function formatErrors(Validator $validator)
{
foreach ($validator->errors()->all() as $error) {
Notifications::add($error, 'danger');
}
return $validator->errors()->getMessages();
}
示例3: formatValidationErrors
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();
}
示例4: failedValidation
/**
* 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);
}
示例5: formatErrors
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;
}
示例6: failedValidation
/**
* 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);
}
示例7: failedValidationResponse
/**
* 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));
}
示例8: throwStoreResourceFailedException
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);
}
}
示例9: formatErrors
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();
}
示例10: formatErrors
/**
* 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];
}
示例11: store
/**
* 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;
}
示例12: formatErrors
/**
* @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;
}
示例13: formatErrors
/**
* @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;
}
示例14: formatErrors
/**
* @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;
}
示例15: formatErrors
/**
* @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;
}