Package

Nathanheffley Laravel Slack Blocks

Slack Blocks support for laravel notifications.

Package

nathanheffley/laravel-slack-blocks

View on GitHub →

Laravel Slack Blocks

This package is an extension of the official laravel/slack-notification-channel package.

Note Thes core notifications package has finally built-in support for these rich Slack messages, and as such you should use the official package if you are able.

https://laravel.com/docs/10.x/notifications#formatting-slack-notifications

Usage

Instead of requiring the official package, you should require this one instead.

composer require nathanheffley/laravel-slack-blocks

Because this package is built on top of the official one, you'll have all the functionality found in the official docs.

You can follow those instructions with the slight adjustment of requiring the classes from NathanHeffley\LaravelSlackBlocks instead of Illuminate\Notifications.

Everything supported in the base Illuminate Notifications classes is supported in these extended classes.

If you want to add a block to your Slack message, you need to add the block in an attachment.

use NathanHeffley\LaravelSlackBlocks\Messages\SlackMessage;

// ...

public function toSlack($notifiable)
{
    return (new SlackMessage)
        ->attachment(function ($attachment) {
            $attachment->block(function ($block) {
                $block
                    ->type('section')
                    ->text([
                        'type' => 'mrkdwn',
                        'text' => '*Hello World!*',
                    ]);
            });
        });
}

To see all the possible fields you can add to a block, check out the official Slack Blocks documentation.

To help, some blocks have been given dedicated helper functions on the attachment model itself. Currently there are methods for adding dividers and images.

(new SlackMessage)->attachment(function ($attachment) {
    $attachment->imageBlock('http://placekitten.com/300/200', 'A cute kitten');
    $attachment->dividerBlock();
    $attachment->imageBlock('http://placekitten.com/300/200', 'A cute kitten', 'This is a titled cat image');
});

Nathanheffley Laravel Slack Blocks Related Articles

A Stand-Alone Laravel Slack Package image

A Stand-Alone Laravel Slack Package

Read article
Laravel Slack Notification Channel Supports BlockKit API image

Laravel Slack Notification Channel Supports BlockKit API

Read article
Laravel Slack Alerts Package image

Laravel Slack Alerts Package

Read article
Laracon Online Slack Is Now Open image

Laracon Online Slack Is Now Open

Read article
Build your own Slack Bot with this PHP library image

Build your own Slack Bot with this PHP library

Read article
Nested Describe Blocks Are Now Available in Pest v3.5 image

Nested Describe Blocks Are Now Available in Pest v3.5

Read article

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm

Let your users buy domains without leaving your app

If your Laravel app gives users a site, a storefront, or a workspace, they’ll eventually want their own domain. The name.com API lets them search, register, and connect one without leaving your product. It’s a clean REST API, so Laravel’s HTTP client is all you need.

Let your users buy domains without leaving your app

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing