本文整理汇总了PHP中Illuminate\Support\MessageBag::getMessages方法的典型用法代码示例。如果您正苦于以下问题:PHP MessageBag::getMessages方法的具体用法?PHP MessageBag::getMessages怎么用?PHP MessageBag::getMessages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\MessageBag
的用法示例。
在下文中一共展示了MessageBag::getMessages方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getErrors
/**
* Returns errors from the validator. This will return only messages
* if the request is from ajax.
*
* @return array|\Illuminate\Support\MessageBag
*/
public function getErrors()
{
if (Request::ajax()) {
return $this->errors->getMessages();
} else {
return $this->errors;
}
}
示例2: formatErrors
/**
* Format the validation errors.
*
* @param \Illuminate\Support\MessageBag $errors
*
* @return mixed
*/
protected function formatErrors($errors)
{
$output = [];
foreach ($errors->getMessages() as $field => $message) {
$output[] = ['code' => 'validation_fails', 'field' => $field, 'message' => isset($message[0]) ? $message[0] : ''];
}
return $output;
}
示例3: testFirstReturnsSingleMessage
public function testFirstReturnsSingleMessage()
{
$container = new MessageBag();
$container->setFormat(':message');
$container->add('foo', 'bar');
$container->add('foo', 'baz');
$messages = $container->getMessages();
$this->assertEquals('bar', $container->first('foo'));
}
示例4: setFlash
/**
* Write all alerts to session flash
*/
public function setFlash()
{
$flash = array();
foreach ($this->bag->getMessages() as $type => $messages) {
foreach ($messages as $message) {
$flash[$type][] = $message;
}
}
$this->session->flash(self::SESSION_KEY, $flash);
}
示例5: getErrors
/**
* get all messages from message bag
*
* @param boolean $raw
* @return mixed
*/
public function getErrors($raw = false)
{
if ($this->errors === null) {
$this->errors = new MessageBag();
}
if ($raw) {
return $this->errors;
}
return $this->errors->getMessages();
}
示例6: validate
public function validate($attributes = [])
{
/* @var $this Model */
if (!method_exists($this, 'rules')) {
return true;
}
$attributes = $attributes ? array_merge($this->getAttributes(), $attributes) : $this->getAttributes();
$validator = Main::$app->connection->validator->make($attributes, $this->rules());
$result = $validator->passes();
if (!$result) {
$this->errors = $validator->errors();
foreach ($this->errors->getMessages() as $errors) {
foreach ($errors as $error) {
Alert::add($error, Alert::ERROR);
}
}
return false;
}
return true;
}
示例7: render
/**
* Show specific alert type
* @param string $type
* @return string
*/
public function render()
{
if ($this->bag->any()) {
$output = array();
foreach ($this->bag->getMessages() as $type => $messages) {
foreach ($messages as $message) {
// Prepare output
$output[] = array('type' => $type, 'data' => $message);
}
}
//$json = new JsonResponse;
//return json_encode($output);
return $output;
}
}
示例8: addCallAnotherErrors
/**
* Method to loop through errors and merge them into parent attribute
* @param string $attribute
* @param integer $index
* @param MessageBag $errors
*/
private function addCallAnotherErrors($attribute, MessageBag $errors)
{
foreach ($errors->getMessages() as $nestedAttribute => $messages) {
foreach ($messages as $message) {
$specifier = $this->makeSpecifier('call_another');
$specifier = str_replace(':attribute', $attribute, $specifier);
$this->messages->add($attribute, "{$specifier} {$message}");
}
}
}
示例9: validation
/**
* Sets a validation error flash message.
*
* @param MessageBag $errors
* @param string $message
*/
public function validation(MessageBag $errors, $message = 'Form validation failed')
{
$this->error($message);
$this->session->flash('flash_notification.validation', $errors->getMessages());
}
示例10: getMessages
/**
* Get the raw messages in the message bag.
*
* @return array
*/
public function getMessages()
{
return $this->messages->getMessages();
}
示例11: mergeErrors
/**
* Merge the errors into the multiple form builder.
*
* @param MessageBag $errors
*/
protected function mergeErrors(MessageBag $errors)
{
foreach ($errors->getMessages() as $field => $message) {
$this->builder->addFormError($field, implode('<br>', $message));
}
}
示例12: error_422
/**
* Validation error.
*
* @param array $messages
* @return string
*/
protected function error_422($messages)
{
// Get message bag from validator.
if ($messages instanceof MessageProviderInterface) {
$messages = $messages->getMessageBag();
}
// Get validation message bag.
if (!$messages instanceof MessageBag) {
$messages = new MessageBag($messages);
}
$content = array();
// Re-format error messages.
foreach ($messages->getMessages() as $field => $message) {
$error = array('field' => $field, 'message' => current($message));
array_push($content, $error);
}
return $this->make($content, 'error_422');
}
示例13: mergeBag
/**
* Merge a message bag
* @param Illuminate\Support\MessageBag $bag
* @return Iyoworks\Support\AlertBag
*/
public function mergeBag(MessageBag $bag)
{
$this->merge($bag->getMessages());
return $this;
}