Laravel Slack Alerts Package

Packages

January 28th, 2022

Laravel Slack Alerts Package

Laravel Slack Alerts is a package by Spatie to send a message to slack quickly. While you can set up Slack notifications in Laravel's robust notification system, sometimes all you need is a simple way to trigger a message in various slack channels:

1use Spatie\SlackAlerts\Facades\SlackAlert;
2 
3SlackAlert::message("{$user->name} just signed up for your Super Awesome SaaS! :party-parrot:");

The above message is sent via a (configurable) job, and you can also configure multiple slack webhook URLs to which you can send messages:

1// config
2return [
3 'webhook_urls' => [
4 'default' => 'https://hooks.slack.com/services/XXXXXX',
5 'marketing' => 'https://hooks.slack.com/services/YYYYYY',
6 ],
7];
8 
9SlackAlert::to('marketing')
10 ->message("{$user->name} just requested a SaaS demo!");

Messages can also contain markdown and Slack emojis.

If you'd like to learn more about the background behind this package, read A package to send Slack alerts in a Laravel app quickly by Freek Van der Herten.

To get started with this package, check it out the readme and source code on GitHub.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.