本文整理汇总了PHP中Illuminate\Support\MessageBag::merge方法的典型用法代码示例。如果您正苦于以下问题:PHP MessageBag::merge方法的具体用法?PHP MessageBag::merge怎么用?PHP MessageBag::merge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\MessageBag
的用法示例。
在下文中一共展示了MessageBag::merge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addError
/**
* Add an error message to the validator's collection of messages.
*
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return void
*/
protected function addError($attribute, $rule, $parameters)
{
$message = $this->getMessage($attribute, $rule);
$message = $this->doReplacements($message, $attribute, $rule, $parameters);
$customMessage = new MessageBag();
$customMessage->merge(['code' => strtolower($rule . '_rule_error')]);
$customMessage->merge(['message' => $message]);
$this->messages->add($attribute, $customMessage);
//dd($this->messages);
}
示例2: validate
public function validate()
{
$validator = App::make('validator');
$rules = $this->processRules($this->model->validationRules);
$this->validator = $validator->make($this->model->toArray(), $rules, $this->model->validationMessages);
if ($this->validator->fails()) {
$this->messageBag = $this->messageBag ? $this->messageBag->merge($this->validator->messages()) : $this->validator->messages();
return false;
}
return true;
}
示例3: error
/**
* 存储错误消息
* @param string|array $key 表单字段名 | 消息列表
* @param string $message 错误消息
* @throws void
*/
public function error($key, $message = '')
{
if (!is_array($key)) {
$key = array($key => $message);
}
$messageBag = new MessageBag($key);
if (is_null(self::$errors)) {
self::$errors = $messageBag;
} else {
self::$errors->merge($messageBag);
}
}
示例4: set
/**
* Set value
* @param string $key
* @param array $fields
* @param string $label
* @return boolean
* @throws \LogicException
*/
public function set($key, &$fields, $label)
{
$value = $this->getValueByKey($fields, $key);
if (isset($this->value)) {
$value = $this->value;
} elseif (isset($this->function)) {
$value = call_user_func_array($this->function, $this->function_params);
} else {
throw new \LogicException("No value for set for param `{$key}`.");
}
if (!$this->isEmpty($value)) {
foreach ($this->validators as $validator) {
$return = $validator->validate($key, $value, $label, $fields);
if ($validator->hasErrors()) {
if ($this->error === null) {
$this->error = new MessageBag();
}
$this->error->merge($validator->getErrors());
}
if (!$return) {
return false;
}
}
}
$fields[$key] = $value;
return true;
}
示例5: putErrors
/**
* Puts more errors in its message bag.
* @return boolean
*/
public function putErrors($errors)
{
if (!is_array($errors) && !$errors instanceof MessageProvider) {
$errors = [$errors];
}
$this->errors->merge($errors);
}
示例6: runValidationChecks
/**
* Run the validation checks in the input data
*
* @param array $data
*
* @return bool
* @throws Exception
* @throws ValidateException
*/
public function runValidationChecks(array $data)
{
foreach ($this->validators as $validator) {
if ($validator instanceof Validator) {
if (!$validator->with($data)->validate()) {
$this->errors->merge($validator->errors());
}
} else {
throw new Exception("{$validator} is not an instance of Motty\\Laravel\\Validator\\Contracts\\Validator");
}
}
if ($this->errors->isEmpty()) {
return true;
}
throw new ValidateException('Validation failed', $this->errors);
}
示例7: withWarnings
/**
* Merge a new array of messages into the warning messages.
*
* @param MessageProvider|array $messages keyed by control name
* @return $this
*/
public function withWarnings($messages)
{
if ($messages instanceof ViewErrorBag) {
$messages = $messages->getMessageBag();
}
$this->warning_messages->merge($messages);
return $this;
}
示例8: messages
/**
* Add new messages into the bag.
*
* @param mixed $messages array, string, \Codenest\Ahem\MessageBag or \Illuminate\Support\MessageBag Instances.
* @return \Codenest\Ahem\Notification
*/
public function messages($messages = array())
{
if (is_object($messages)) {
$this->messages->merge($messages->getMessages());
} elseif (is_array($messages)) {
$this->messages->merge($messages);
} else {
$this->messages->merge(array($messages));
}
return $this;
}
示例9: gatherErrors
/**
* Gather and merge import errors from
* related model importers.
*/
public function gatherErrors()
{
foreach ($this->parents as $parent) {
$parent->gatherErrors();
$this->errorMessageBag->merge($parent->errors());
}
foreach ($this->children as $child) {
$child->gatherErrors();
$this->errorMessageBag->merge($child->errors());
}
}
示例10: valid
/**
* Validate a set of attributes against a certain action.
*
* @param string $action
* @param array $attributes
*
* @return boolean
*/
public function valid($action, array $attributes)
{
if ($this->validator === null) {
return true;
}
$result = $this->validator->valid($action, $attributes);
if ($result === false) {
$this->errors->merge($this->validator->getErrors());
}
return $result;
}
示例11: validateNestedValidations
/**
* Validates nested validators using previously bound input.
*
* @param mixed $options
*/
protected function validateNestedValidations($options = array())
{
foreach ($this->nestedValidations as $prefix => $validation) {
$validation->validate($options);
// if valdation fails, add any messages to the message bag
if ($validation->driver()->fails()) {
$this->hasPassed = false;
// Add the validation prefix to each message to ensure there aren't conflicts
$messages = $this->applyPrefix($prefix, $validation->driver()->messages());
// Merge the messages into the current message bag
$this->messageBag->merge($validation->driver()->messages());
}
}
}
示例12: asValidator
/**
* @return \Illuminate\Http\JsonResponse|null
* @throws BadEventResultException
*/
public function asValidator()
{
$fails = false;
$errors = new MessageBag();
/** @var Validator $validator */
foreach ($this->events() as $validator) {
$this->validateValidationEventResponse($validator);
if ($validator->fails()) {
$fails = true;
$errors->merge($validator->getMessageBag()->toArray());
}
}
if ($fails) {
return response()->json($errors, 422);
}
return null;
}
示例13: validateNewFields
/**
* Checks if the input request is doable
*
* @param array $fields
* @param $moduleId
*
* @return true|MessageBag
*/
private function validateNewFields(array $fields = array(), $moduleId)
{
$customBag = new MessageBag();
// Main bag
$validatorBags = array();
// Bags of different validators
$takenColumnNames = array();
// Column names that already exist
// Check if column name already exists
$tmpField = new Field();
$rules = array_merge($tmpField->getRules(), array('column_name' => 'unique:fields,column_name,NULL,id,module_id,' . $moduleId));
// Go through all fields and validate them
foreach ($fields as $field) {
$photonField = new Field($field);
$formField = FieldFactory::make($photonField);
$formField->setRow($field);
$validated = $formField->validate();
if ($validated instanceof MessageBag) {
$validatorBags[] = $validated;
}
/* @var $validator \Illuminate\Validation\Validator */
$validator = \Validator::make($field, $rules);
if ($validator->fails()) {
$validatorBags[] = $validator->getMessageBag();
}
if (in_array($field['column_name'], $takenColumnNames)) {
$customBag->add('new_field', 'Column name `' . $field['column_name'] . '` cannot be assigned to multiple fields');
}
$takenColumnNames[] = $field['column_name'];
}
// Merge all bags
/* @var $bag MessageBag */
foreach ($validatorBags as $bag) {
$customBag->merge($bag->getMessages());
}
// Return the bag if there are no errors, otherwise return true
return $customBag->isEmpty() ? true : $customBag;
}
示例14: validate
/**
* Validates current attributes against rules.
*/
public function validate($model = null)
{
if (isset($this->attributes['created_at']) && isset($this->attributes[$this->primaryKey])) {
foreach ($this->rules as $key => $rule) {
if (strpos($rule, 'unique:') !== false) {
$rulesCol = explode('|', $rule);
foreach ($rulesCol as $key2 => $val) {
if (starts_with($rulesCol[$key2], 'unique:')) {
$rulesCol[$key2] .= ',' . $this->{$this->primaryKey} . ',' . $this->primaryKey;
}
}
$this->rules[$key] = implode('|', $rulesCol);
}
}
}
$v = $this->validator->make($this->attributes, $this->rules);
$v->setAttributeNames($this->getPrettyFields());
if ($v->passes() && $this->verificarConcurrencia()) {
$this->afterValidate();
return true;
}
$this->errors->merge($v->messages());
return false;
}
示例15: mergeErrors
/**
* Merge two message bags together
*
* @param \Illuminate\Support\MessageBag $bag
* @param \Illuminate\Support\MessageBag $errors
* @param integer $index
* @return \Illuminate\Support\MessageBag
*/
private function mergeErrors(MessageBag $bag, MessageBag $errors, $index = null)
{
if (!$errors->count()) {
return $bag;
}
// Add or merge errors into bag
if ($index !== null) {
$bag->add($index, $errors);
} else {
$bag->merge($errors);
}
return $bag;
}