Skip to content

Commit

Permalink
Document partition and markdown attachment content.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 16, 2017
1 parent 4fe2999 commit ecc1751
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
12 changes: 12 additions & 0 deletions collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ For the remainder of this documentation, we'll discuss each method available on
[min](#method-min)
[nth](#method-nth)
[only](#method-only)
[partition](#method-partition)
[pipe](#method-pipe)
[pluck](#method-pluck)
[pop](#method-pop)
Expand Down Expand Up @@ -801,6 +802,17 @@ The `only` method returns the items in the collection with the specified keys:

For the inverse of `only`, see the [except](#method-except) method.

<a name="method-partition"></a>
#### `partition()` {#collection-method}

The `partition` method may be combined with the `list` PHP function to separate elements that pass a given truth test from those that do not:

$collection = collect([1, 2, 3, 4, 5, 6]);

list($underThree, $aboveThree) = $collection->partition(function ($i) {
return $i < 3;
});

<a name="method-pipe"></a>
#### `pipe()` {#collection-method}

Expand Down
38 changes: 32 additions & 6 deletions notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- [Slack Notifications](#slack-notifications)
- [Prerequisites](#slack-prerequisites)
- [Formatting Slack Notifications](#formatting-slack-notifications)
- [Slack Attachments](#slack-attachments)
- [Routing Slack Notifications](#routing-slack-notifications)
- [Notification Events](#notification-events)
- [Custom Channels](#custom-channels)
Expand Down Expand Up @@ -579,7 +580,26 @@ In this example we are just sending a single line of text to Slack, which will c

<img src="https://laravel.com/assets/img/basic-slack-notification.png">

#### Slack Attachments
#### Customizing The Sender & Recipient

You may use the `from` and `to` methods to customize the sender and recipient. The `from` method accepts a username and emoji identifier, while the `to` method accepts a channel or username:

/**
* Get the Slack representation of the notification.
*
* @param mixed $notifiable
* @return SlackMessage
*/
public function toSlack($notifiable)
{
return (new SlackMessage)
->from('Ghost', ':ghost:')
->to('#other')
->content('This will be sent to #other');
}

<a name="slack-attachments"></a>
### Slack Attachments

You may also add "attachments" to Slack messages. Attachments provide richer formatting options than simple text messages. In this example, we will send an error notification about an exception that occurred in an application, including a link to view more details about the exception:

Expand Down Expand Up @@ -636,9 +656,9 @@ The example above will create a Slack message that looks like the following:

<img src="https://laravel.com/assets/img/slack-fields-attachment.png">

#### Customizing The Sender & Recipient
#### Markdown Attachment Content

You may use the `from` and `to` methods to customize the sender and recipient. The `from` method accepts a username and emoji identifier, while the `to` method accepts a channel or username:
If some of your attachment fields contain Markdown, you may use the `markdown` method to instruct Slack to parse and display the given attachment fields as Markdown formatted text:

/**
* Get the Slack representation of the notification.
Expand All @@ -648,10 +668,16 @@ You may use the `from` and `to` methods to customize the sender and recipient. T
*/
public function toSlack($notifiable)
{
$url = url('/exceptions/'.$this->exception->id);

return (new SlackMessage)
->from('Ghost', ':ghost:')
->to('#other')
->content('This will be sent to #other');
->error()
->content('Whoops! Something went wrong.')
->attachment(function ($attachment) use ($url) {
$attachment->title('Exception: File Not Found', $url)
->content('File [background.jpg] was **not found**.')
->markdown(['title', 'text']);
});
}

<a name="routing-slack-notifications"></a>
Expand Down

0 comments on commit ecc1751

Please sign in to comment.