当前位置: 首页>>代码示例>>PHP>>正文


PHP Validator::messages方法代码示例

本文整理汇总了PHP中Illuminate\Validation\Validator::messages方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::messages方法的具体用法?PHP Validator::messages怎么用?PHP Validator::messages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Validation\Validator的用法示例。


在下文中一共展示了Validator::messages方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: messages

 /**
  * @return array|MessageBag
  */
 public function messages() : array
 {
     if ($this->validation === null) {
         return [];
     }
     return $this->validation->messages();
 }
开发者ID:hughgrigg,项目名称:ching-shop,代码行数:10,代码来源:IlluminateValidation.php

示例2: getErrorMessages

 public function getErrorMessages()
 {
     $allMessages = $this->validator->messages()->getMessages();
     if (!$this->reportIlluminateErrors) {
         $availableErrorMessages = $this->form->bootErrorMessages();
         $plainMessages = [];
         foreach ($allMessages as $fieldName => $message) {
             $message = isset($availableErrorMessages[$fieldName]) ? $availableErrorMessages[$fieldName] : "{attribute} is not valid";
             $message = str_replace('{:attribute}', '{' . $fieldName . '}', $message);
             // array of 1 element for compatibility with Laravel's MessageBag
             $plainMessages[$fieldName] = [$message];
         }
         $allMessages = $plainMessages;
     }
     foreach ($allMessages as $fieldName => &$messages) {
         foreach ($messages as &$message) {
             $searchField = str_replace('_', ' ', $fieldName);
             $searchField = '{' . $searchField . '}';
             $element = $this->form->el($fieldName);
             /* @var $element Element */
             $replace = [$searchField => $element->label, '{value}' => htmlspecialchars($element->val(), ENT_NOQUOTES, 'UTF-8')];
             // for choice elements add option to output the text value of an option
             if ($element instanceof Choice) {
                 $replace['{valueText}'] = $element->valueText();
             }
             $message = str_replace(array_keys($replace), array_values($replace), $message);
         }
         $messages = implode(', ', $messages);
     }
     return $allMessages;
 }
开发者ID:okneloper,项目名称:forms,代码行数:31,代码来源:IlluminateValidator.php

示例3: getMessages

 public function getMessages()
 {
     if ($this->_validator !== null) {
         return $this->_validator->messages()->getMessages();
     } else {
         return $this->_messages;
     }
 }
开发者ID:nsystem1,项目名称:Pony.fm,代码行数:8,代码来源:CommandResponse.php

示例4: getValidationErrors

 /**
  * Return the validation errors with :field-:message format
  *
  * @return mixed
  */
 public function getValidationErrors()
 {
     $errors = [];
     $messages = $this->validation->messages();
     foreach ($messages->getMessages() as $key => $message) {
         $errors[$key] = $message[0];
     }
     return $errors;
 }
开发者ID:xintang22,项目名称:Paxifi,代码行数:14,代码来源:Validator.php

示例5: validate

 public function validate(\Illuminate\Validation\Validator $validator)
 {
     if ($validator->fails()) {
         $this->validation_errors = $validator->messages();
         return false;
     }
     return true;
 }
开发者ID:fredlawl,项目名称:planebox-api,代码行数:8,代码来源:PlaneBoxModel.php

示例6: failedValidation

 /**
  * Alias for displaying validation errors.
  * @param Validator $validator
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public static function failedValidation(Validator $validator)
 {
     $response = static::create(null, 406);
     foreach ($validator->messages()->all() as $msg) {
         $response->error($msg, 0);
     }
     return $response;
 }
开发者ID:breachofmind,项目名称:birdmin,代码行数:13,代码来源:RESTResponse.php

示例7: validateOrFail

 public function validateOrFail($additional = array())
 {
     $attributes = $this->getAttributes();
     $this->validator = \Validator::make($attributes, $this->prepareRules());
     if ($this->validator->fails()) {
         $messages = $this->validator->messages();
         foreach ($attributes as $key => $value) {
             if ($messages->has($key)) {
                 foreach ($messages->get($key) as $message) {
                     $additional['attribute'] = $key;
                     $this->errors->add(new Error($message, '', $additional));
                 }
             }
         }
         throw new ValidationException($this->errors->errors());
     }
     return true;
 }
开发者ID:AniartUA,项目名称:crm,代码行数:18,代码来源:BaseModel.php

示例8:

 function it_returns_messages_on_failed_validation(Validator $validator, MessageBag $bag)
 {
     $validator->setData($data = [])->shouldBeCalled();
     $validator->passes()->willReturn(false);
     $validator->messages()->willReturn($bag);
     $bag->all()->willReturn($messages = ['foo' => 'failed']);
     $this->validate($data)->shouldReturn(false);
     $this->getMessages()->shouldReturn($messages);
 }
开发者ID:desmart,项目名称:deform-laravel,代码行数:9,代码来源:ValidatorAdapterSpec.php

示例9: validate

 /**
  * Validate data.
  *
  * @author Morten Rugaard <moru@nodes.dk>
  *
  * @return bool
  * @throws \Nodes\Validation\Exceptions\ValidationException
  */
 public function validate()
 {
     // Generate validator instance
     $this->validator = $this->validatorFactory->make($this->getData(), $this->getRules(), $this->getMessages(), $this->getAttributes());
     // Validation was a success!
     if (!$this->validator->fails()) {
         return true;
     }
     // Collect validation errors
     $this->errors = $this->validator->messages();
     return false;
 }
开发者ID:nodes-php,项目名称:validation,代码行数:20,代码来源:AbstractValidator.php

示例10: validateData

 /**
  * Validates the supplied data against the options rules
  *
  * @param array		$data
  * @param array		$rules
  * @param array		$messages
  *
  * @param mixed
  */
 public function validateData(array $data, array $rules, array $messages)
 {
     if ($rules) {
         $this->customValidator->setData($data);
         $this->customValidator->setRules($rules);
         $this->customValidator->setCustomMessages($messages);
         //if the validator fails, kick back the errors
         if ($this->customValidator->fails()) {
             return implode('. ', $this->customValidator->messages()->all());
         }
     }
     return true;
 }
开发者ID:dmitriyuch,项目名称:Laravel-Administrator,代码行数:22,代码来源:Config.php

示例11: valid

 /**
  * Returns whether the current state of the validator is valid.
  *
  * @param bool $partial Whether a partial validation is okay.
  * @return bool
  */
 public function valid($partial = false)
 {
     if ($partial) {
         $this->useFields(array_keys($this->values));
     }
     // Generate our implementation from the app.
     $this->validator = self::$factory->make($this->values, $this->rules);
     if ($this->validator->passes()) {
         return true;
     }
     $this->errors = $this->validator->messages();
     return false;
 }
开发者ID:tippingcanoe,项目名称:validator,代码行数:19,代码来源:Base.php

示例12: validate

 /**
  * Validate the model instance
  *
  * @param array $rules            Validation rules
  * @param array $customMessages   Custom error messages
  * @param array $customAttributes Custom attributes
  * @return bool
  * @throws InvalidModelException
  */
 public function validate(array $rules = array(), array $customMessages = array(), array $customAttributes = array())
 {
     if ($this->fireModelEvent('validating') === false) {
         if ($this->throwOnValidation) {
             throw new InvalidModelException($this);
         } else {
             return false;
         }
     }
     // check for overrides, then remove any empty rules
     $rules = empty($rules) ? static::$rules : $rules;
     foreach ($rules as $field => $rls) {
         if ($rls == '') {
             unset($rules[$field]);
         }
     }
     if (empty($rules)) {
         $success = true;
     } else {
         $customMessages = empty($customMessages) ? static::$customMessages : $customMessages;
         $customAttributes = empty($customAttributes) ? static::$customAttributes : $customAttributes;
         if ($this->forceEntityHydrationFromInput || empty($this->attributes) && $this->autoHydrateEntityFromInput) {
             $this->fill(Input::all());
         }
         $data = $this->getAttributes();
         // the data under validation
         // perform validation
         $this->validator = static::makeValidator($data, $rules, $customMessages, $customAttributes);
         $success = $this->validator->passes();
         if ($success) {
             // if the model is valid, unset old errors
             if ($this->validationErrors === null || $this->validationErrors->count() > 0) {
                 $this->validationErrors = new MessageBag();
             }
         } else {
             // otherwise set the new ones
             $this->validationErrors = $this->validator->messages();
             // stash the input to the current session
             if (!self::$externalValidator && Input::hasSession()) {
                 Input::flash();
             }
         }
     }
     $this->fireModelEvent('validated', false);
     if (!$success && $this->throwOnValidation) {
         throw new InvalidModelException($this);
     }
     return $success;
 }
开发者ID:weyforth,项目名称:ardent,代码行数:58,代码来源:Ardent.php

示例13: update

 /**
  * @param $id
  * @param $data
  * @return $this|\Illuminate\Http\RedirectResponse
  */
 public function update($id, $data)
 {
     if (!$this->validate($data)) {
         return back()->withInput()->withErrors($this->validator->messages());
     }
     $this->model = $this->model->with($this->getRelations())->findOrFail($id);
     $this->setFieldOriginalValue();
     $this->prepare($data, $this->saving);
     DB::transaction(function () {
         $updates = $this->prepareUpdate($this->updates);
         foreach ($updates as $column => $value) {
             $this->model->setAttribute($column, $value);
         }
         $this->model->save();
         $this->updateRelation($this->relations);
     });
     return redirect($this->resource());
 }
开发者ID:zhangsong,项目名称:laravel-admin,代码行数:23,代码来源:Form.php

示例14: update

 /**
  * @param $id
  * @param $data
  * @return $this|\Illuminate\Http\RedirectResponse
  */
 public function update($id, $data)
 {
     if (!$this->validate($data)) {
         return back()->withInput()->withErrors($this->validator->messages());
     }
     $this->model = $this->model->with($this->getRelations())->findOrFail($id);
     $this->setFieldOriginalValue();
     $updates = array_filter($data, 'is_string');
     $relations = array_filter($data, 'is_array');
     DB::transaction(function () use($updates, $relations) {
         $updates = $this->prepareUpdate($updates);
         foreach ($updates as $column => $value) {
             $this->model->setAttribute($column, $value);
         }
         $this->model->save();
         foreach ($relations as $name => $values) {
             if (!method_exists($this->model, $name)) {
                 continue;
             }
             $prepared = $this->prepareUpdate([$name => $values]);
             if (empty($prepared)) {
                 continue;
             }
             $relation = $this->model->{$name}();
             switch (get_class($relation)) {
                 case \Illuminate\Database\Eloquent\Relations\BelongsToMany::class:
                     $relation->sync($prepared[$name]);
                     break;
                 case \Illuminate\Database\Eloquent\Relations\HasOne::class:
                     foreach ($prepared[$name] as $column => $value) {
                         $this->model->{$name}->setAttribute($column, $value);
                     }
                     $this->model->{$name}->save();
                     break;
             }
         }
     });
     return redirect($this->resource());
 }
开发者ID:barryzhang,项目名称:laravel-admin,代码行数:44,代码来源:Form.php

示例15: throwException

 /**
  * @param Validator $validator
  *
  * @throws CommandValidationException
  */
 protected function throwException(Validator $validator)
 {
     throw new CommandValidationException($validator->messages());
 }
开发者ID:adamgoose,项目名称:commander,代码行数:9,代码来源:CommandValidator.php


注:本文中的Illuminate\Validation\Validator::messages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。