Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Laravel Slack Blocks

nathanheffley/laravel-slack-blocks image

Laravel Slack Blocks stats

Downloads
278K
Stars
49
Open Issues
1
Forks
11

View on GitHub →

Slack Blocks support for laravel notifications.

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 photo

PHP and JavaScript developer. Developing internal tools, Playdate games, and running @lancasterlaravel

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Nathanheffley Laravel Slack Blocks Related Articles

Fusion Developer Preview is released: Write PHP inside your Vue and React components image

Fusion Developer Preview is released: Write PHP inside your Vue and React components

Read article
PhpStorm logo

PhpStorm

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

PhpStorm
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
DreamzTech logo

DreamzTech

Hire 6-10+ Yrs. experienced skilled Laravel Developers from DreamzTech. We ensure NDA protected, 100% quality delivery. Contact Us & Discuss Your Need.

DreamzTech
CodeKudu logo

CodeKudu

Stand-ups, Retrospectives, and 360° Feedback for the entire team. 50% off with code LARAVELNEWS.

CodeKudu
Typesense Search logo

Typesense Search

Typesense is an open source, blazing-fast search engine, optimized for helping you build delightful search experiences for your sites and apps. Natively integrated with Laravel Scout.

Typesense Search