class MessageBag implements Countable, Jsonable, JsonSerializable, MessageBag, MessageProvider, Stringable, Transient

Properties

protected array<array-key, string[]> $messages

All of the registered messages.

protected string $format

Default format for message output.

Methods

__construct(array $messages = [])

Create a new message bag instance.

array
keys()

Get the keys present in the message bag.

add(string $key, string $message)

Add a message to the message bag.

addIf(bool $boolean, string $key, string $message)

Add a message to the message bag if the given conditional is "true".

bool
isUnique(string $key, string $message)

Determine if a key and message combination already exists.

merge(MessageProvider|array $messages)

Merge a new array of messages into the message bag.

bool
has(array|string|null $key = null)

Determine if messages exist for all of the given keys.

bool
hasAny(array|string|null $keys = [])

Determine if messages exist for any of the given keys.

bool
missing(array|string|null $key = null)

Determine if messages don't exist for all of the given keys.

string
first(string|null $key = null, string|null $format = null)

Get the first message from the message bag for a given key.

array
get(string $key, string|null $format = null)

Get all of the messages from the message bag for a given key.

array
getMessagesForWildcardKey(string $key, string|null $format)

Get the messages for a wildcard key.

array
all(string|null $format = null)

Get all of the messages for every key in the message bag.

array
unique(string|null $format = null)

Get all of the unique messages for every key in the message bag.

forget(string $key)

Remove a message from the message bag.

array
transform(array $messages, string $format, int|string $messageKey)

Format an array of messages.

string
checkFormat(string|null $format)

Get the appropriate format based on the given format.

array
messages()

Get the raw messages in the message bag.

array
getMessages()

Get the raw messages in the message bag.

getMessageBag()

Get the messages for the instance.

string
getFormat()

Get the default message format.

setFormat(string $format = ':message')

Set the default message format.

bool
isEmpty()

Determine if the message bag has any messages.

bool
isNotEmpty()

Determine if the message bag has any messages.

bool
any()

Determine if the message bag has any messages.

int
count()

Get the number of messages in the message bag.

array
toArray()

Get the instance as an array.

array
jsonSerialize()

Convert the object into something JSON serializable.

string
toJson(int $options = 0)

Convert the object to its JSON representation.

string
toPrettyJson(int $options = 0)

Convert the object to pretty print formatted JSON.

string
__toString()

Convert the message bag to its string representation.

Details

at line 36
__construct(array $messages = [])

Create a new message bag instance.

Parameters

array $messages

at line 50
array keys()

Get the keys present in the message bag.

Return Value

array

at line 60
MessageBag add(string $key, string $message)

Add a message to the message bag.

Parameters

string $key
string $message

Return Value

MessageBag

at line 74
MessageBag addIf(bool $boolean, string $key, string $message)

Add a message to the message bag if the given conditional is "true".

Parameters

bool $boolean
string $key
string $message

Return Value

MessageBag

at line 82
protected bool isUnique(string $key, string $message)

Determine if a key and message combination already exists.

Parameters

string $key
string $message

Return Value

bool

at line 93
MessageBag merge(MessageProvider|array $messages)

Merge a new array of messages into the message bag.

Parameters

MessageProvider|array $messages

Return Value

MessageBag

at line 120
bool has(array|string|null $key = null)

Determine if messages exist for all of the given keys.

Parameters

array|string|null $key

Return Value

bool

at line 147
bool hasAny(array|string|null $keys = [])

Determine if messages exist for any of the given keys.

Parameters

array|string|null $keys

Return Value

bool

at line 170
bool missing(array|string|null $key = null)

Determine if messages don't exist for all of the given keys.

Parameters

array|string|null $key

Return Value

bool

at line 180
string first(string|null $key = null, string|null $format = null)

Get the first message from the message bag for a given key.

Parameters

string|null $key
string|null $format

Return Value

string

at line 194
array get(string $key, string|null $format = null)

Get all of the messages from the message bag for a given key.

Parameters

string $key
string|null $format

Return Value

array

at line 219
protected array getMessagesForWildcardKey(string $key, string|null $format)

Get the messages for a wildcard key.

Parameters

string $key
string|null $format

Return Value

array

at line 234
array all(string|null $format = null)

Get all of the messages for every key in the message bag.

Parameters

string|null $format

Return Value

array

at line 256
array unique(string|null $format = null)

Get all of the unique messages for every key in the message bag.

Parameters

string|null $format

Return Value

array

at line 266
MessageBag forget(string $key)

Remove a message from the message bag.

Parameters

string $key

Return Value

MessageBag

at line 279
protected array transform(array $messages, string $format, int|string $messageKey)

Format an array of messages.

Parameters

array $messages
string $format
int|string $messageKey

Return Value

array

at line 297
protected string checkFormat(string|null $format)

Get the appropriate format based on the given format.

Parameters

string|null $format

Return Value

string

at line 307
array messages()

Get the raw messages in the message bag.

Return Value

array

at line 317
array getMessages()

Get the raw messages in the message bag.

Return Value

array

at line 325
MessageBag getMessageBag()

Get the messages for the instance.

Return Value

MessageBag

at line 333
string getFormat()

Get the default message format.

Return Value

string

at line 343
MessageBag setFormat(string $format = ':message')

Set the default message format.

Parameters

string $format

Return Value

MessageBag

at line 353
bool isEmpty()

Determine if the message bag has any messages.

Return Value

bool

at line 361
bool isNotEmpty()

Determine if the message bag has any messages.

Return Value

bool

at line 369
bool any()

Determine if the message bag has any messages.

Return Value

bool

at line 377
int count()

Get the number of messages in the message bag.

Return Value

int

at line 387
array toArray()

Get the instance as an array.

Return Value

array

at line 397
array jsonSerialize()

Convert the object into something JSON serializable.

Return Value

array

at line 407
string toJson(int $options = 0)

Convert the object to its JSON representation.

Parameters

int $options

Return Value

string

Exceptions

JsonException

at line 417
string toPrettyJson(int $options = 0)

Convert the object to pretty print formatted JSON.

Parameters

int $options

Return Value

string

Exceptions

JsonException

at line 425
string __toString()

Convert the message bag to its string representation.

Return Value

string