---
title: Messages
---

# Messages

<div class="documentation__toc"></div>

@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

<table class="table table-bordered table-striped">

<thead>

<tr>

<th>Key</th>

<th>Required</th>

<th>Type</th>

<th>Default</th>

<th>Description</th>

</tr>

</thead>

<tbody>

<tr>

<td>

$type

</td>

<td>

true

</td>

<td>

string

</td>

<td>

none

</td>

<td>

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

</td>

</tr>

</tbody>

</table>

#### Example

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

### MessageBag::get()

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

##### Returns: `array`

##### Arguments

<table class="table table-bordered table-striped">

<thead>

<tr>

<th>Key</th>

<th>Required</th>

<th>Type</th>

<th>Default</th>

<th>Description</th>

</tr>

</thead>

<tbody>

<tr>

<td>

$type

</td>

<td>

true

</td>

<td>

string

</td>

<td>

none

</td>

<td>

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

</td>

</tr>

</tbody>

</table>

##### 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

<table class="table table-bordered table-striped">

<thead>

<tr>

<th>Key</th>

<th>Required</th>

<th>Type</th>

<th>Default</th>

<th>Description</th>

</tr>

</thead>

<tbody>

<tr>

<td>

$type

</td>

<td>

true

</td>

<td>

string

</td>

<td>

none

</td>

<td>

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

</td>

</tr>

</tbody>

</table>

##### 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

<table class="table table-bordered table-striped">

<thead>

<tr>

<th>Key</th>

<th>Required</th>

<th>Type</th>

<th>Default</th>

<th>Description</th>

</tr>

</thead>

<tbody>

<tr>

<td>

$message

</td>

<td>

true

</td>

<td>

string

</td>

<td>

none

</td>

<td>

The error message to display.

</td>

</tr>

</tbody>

</table>

#### 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

<table class="table table-bordered table-striped">

<thead>

<tr>

<th>Key</th>

<th>Required</th>

<th>Type</th>

<th>Default</th>

<th>Description</th>

</tr>

</thead>

<tbody>

<tr>

<td>

$message

</td>

<td>

true

</td>

<td>

string

</td>

<td>

none

</td>

<td>

The informational message to display.

</td>

</tr>

</tbody>

</table>

#### 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

<table class="table table-bordered table-striped">

<thead>

<tr>

<th>Key</th>

<th>Required</th>

<th>Type</th>

<th>Default</th>

<th>Description</th>

</tr>

</thead>

<tbody>

<tr>

<td>

$message

</td>

<td>

true

</td>

<td>

string

</td>

<td>

none

</td>

<td>

The warning message to display.

</td>

</tr>

</tbody>

</table>

#### Example

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

### MessageBag::success()

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

#### Arguments

<table class="table table-bordered table-striped">

<thead>

<tr>

<th>Key</th>

<th>Required</th>

<th>Type</th>

<th>Default</th>

<th>Description</th>

</tr>

</thead>

<tbody>

<tr>

<td>

$message

</td>

<td>

true

</td>

<td>

string

</td>

<td>

none

</td>

<td>

The success message to display.

</td>

</tr>

</tbody>

</table>

#### Example

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