Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Add fluent builder for SlackMessageAttachmentField #16535

Merged
merged 5 commits into from
Nov 28, 2016
Merged

[5.3] Add fluent builder for SlackMessageAttachmentField #16535

merged 5 commits into from
Nov 28, 2016

Conversation

freekmurze
Copy link
Contributor

@freekmurze freekmurze commented Nov 24, 2016

Currently Laravel only has a fields method to attach some fields to a SlackAttachment

The example from the documentation:

 return (new SlackMessage)
                ->success()
                ->content('One of your invoices has been paid!')
                ->attachment(function ($attachment) use ($url) {
                    $attachment->title('Invoice 1322', $url)
                               ->fields([
                                    'Title' => 'Server Expenses',
                                    'Amount' => '$1,234',
                                    'Via' => 'American Express',
                                    'Was Overdue' => ':-1:',
                                ]);
                });

That's nice, but under the hood the short property of the fields is being set to false. For longer text in attachment there's no way to set this to true. So, an attachment like this (taken from the Slack docs) isn't possible.

attachment_fields

This PR adds a builder for a SlackMessageAttachmentField in the same spirit as SlackMessageAttachment. Using this builder the short property can be set to true by calling the doNotDisplaySideBySide-method.

Here's how the builder can be used:

//in a Notification

public function toSlack($notifiable)
    {
        return (new SlackMessage)
            ->content('Content')
            ->attachment(function ($attachment) {
                $attachment
                    ->title('Laravel', 'https://laravel.com')
                    ->content('Attachment Content')

                    //build up an attachment field
                    ->field(function($attachmentField) {
                        $attachmentField
                            ->title('Special powers')
                            ->content('Zonda')
                            ->dontDisplaySideBySide();
                    });

                    //manually add one
                    ->field('Project', 'Laravel')
            });
    }

Hope you'll like it!

@taylorotwell taylorotwell merged commit 759c31b into laravel:5.3 Nov 28, 2016
@freekmurze freekmurze deleted the feature-short-slack-attachments branch November 28, 2016 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants