當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。