Messages

@TODO remove Laravel links to preserve version integrity

The Anomaly\Streams\Platform\Message\MessageBag class helps flash messages to users like validation errors and success messages.

Basic Usage

Include the Anomaly\Streams\Platform\Message\MessageBag class in your code to get started.

MessageBag::has()

The has method returns whether or not the message bag has any messages of the specified $type.

Returns: bool

Arguments

Key Required Type Default Description

$type

true

string

none

The type of message to check for. Available options are success, info, warning, and danger.

Example

if ($messages->has('success')) {
    die('Oh goodie!');
}

MessageBag::get()

The get method returns all messages of the specified $type.

Returns: array
Arguments
Key Required Type Default Description

$type

true

string

none

The type of message to check for. Available options are success, info, warning, and danger.

Example
foreach ($messages->get('success') as $message) {
    echo $message . '<br>';
}

MessageBag::pull()

The pull method pulls all messages of a specified $type out of the message bag. Removing them from the session data.

Returns: array
Arguments
Key Required Type Default Description

$type

true

string

none

The type of message to check for. Available options are success, info, warning, and danger.

Example
foreach ($messages->pull('success') as $message) {
    echo $message . '<br>'
}

MessageBag::error()

The error method pushes an error message into the message bag.

Returns: Anomaly\Streams\Platform\Message\MessageBag

Arguments

Key Required Type Default Description

$message

true

string

none

The error message to display.

Example

$messages->error('Ah snap! It broke.');

MessageBag::info()

The info method pushes an informational message into the message bag.

Returns: Anomaly\Streams\Platform\Message\MessageBag

Arguments

Key Required Type Default Description

$message

true

string

none

The informational message to display.

Example

$messages->info('You know what? Ya me neither.');

MessageBag::warning()

The warning method pushes a warning message into the message bag.

Returns: Anomaly\Streams\Platform\Message\MessageBag

Arguments

Key Required Type Default Description

$message

true

string

none

The warning message to display.

Example

$messages->warning('You had better watch it sparky.');

MessageBag::success()

The success method pushes a success message into the message bag.

Arguments

Key Required Type Default Description

$message

true

string

none

The success message to display.

Example

$messages->success('You win!');