PHPackages                             spatie/laravel-slack-alerts - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. spatie/laravel-slack-alerts

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

spatie/laravel-slack-alerts
===========================

Send a message to Slack

1.9.0(2mo ago)3212.6M—6.2%41[1 PRs](https://github.com/spatie/laravel-slack-alerts/pulls)3MITPHPPHP ^8.2CI passing

Since Jan 4Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/spatie/laravel-slack-alerts)[ Packagist](https://packagist.org/packages/spatie/laravel-slack-alerts)[ Docs](https://github.com/spatie/laravel-slack-alerts)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/spatie-laravel-slack-alerts/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (22)Versions (27)Used By (3)

Quickly send a message to Slack
===============================

[](#quickly-send-a-message-to-slack)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0c50838678c29b0d50eb6862ee89f57e6c0a513d6257327bad071d99bc151aef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d736c61636b2d616c657274732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-slack-alerts)[![run-tests](https://github.com/spatie/laravel-slack-alerts/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-slack-alerts/actions/workflows/run-tests.yml)[![Check & fix styling](https://github.com/spatie/laravel-slack-alerts/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/spatie/laravel-slack-alerts/actions/workflows/php-cs-fixer.yml)[![Total Downloads](https://camo.githubusercontent.com/abfdb928b3b3cb5e68f4196b2f247da82add4fafff57019e962dea26e6ac04bd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d736c61636b2d616c657274732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-slack-alerts)

This package can quickly send alerts to Slack. You can use this to notify yourself of any noteworthy events happening in your app.

```
use Spatie\SlackAlerts\Facades\SlackAlert;

SlackAlert::message("You have a new subscriber to the {$newsletter->name} newsletter!");
```

Under the hood, a job is used to communicate with Slack. This prevents your app from failing in case Slack is down.

Want to send alerts to Discord instead? Check out [laravel-discord-alerts](https://github.com/spatie/laravel-discord-alerts).

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/ca8fd9d46f6e6e0e8ffe9cecb3237fd19cf9b38dba85700f49caaa1ba7eb4feb/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d736c61636b2d616c657274732e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-slack-alerts)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/laravel-slack-alerts
```

You can set a `SLACK_ALERT_WEBHOOK` env variable containing a valid Slack webhook URL. You can learn how to get a webhook URL [in the Slack API docs](https://api.slack.com/messaging/webhooks).

Alternatively, you can publish the config file with:

```
php artisan vendor:publish --tag="slack-alerts-config"
```

This is the contents of the published config file:

```
return [
    /*
     * Whether the slack alerts are enabled.
     */
    'enabled' => env('SLACK_ALERT_ENABLED', true),

    /*
     * The webhook URLs that we'll use to send a message to Slack.
     */
    'webhook_urls' => [
        'default' => env('SLACK_ALERT_WEBHOOK'),
    ],

    /*
     * This job will send the message to Slack. You can extend this
     * job to set timeouts, retries, etc...
     */
    'job' => Spatie\SlackAlerts\Jobs\SendToSlackChannelJob::class,
    'queue' => env('SLACK_ALERT_QUEUE', 'default'),
];
```

Usage
-----

[](#usage)

To send a message to Slack, simply call `SlackAlert::message()` and pass it any message you want.

```
SlackAlert::message("You have a new subscriber to the {$newsletter->name} newsletter!");
```

Sending blocks
--------------

[](#sending-blocks)

Slack supports sending rich formatting using their [Block Kit](https://api.slack.com/block-kit) API, you can send a set of blocks using the `blocks()` method:

```
SlackAlert::blocks([
    [
        "type" => "section",
        "text" => [
        "type" => "mrkdwn",
            "text" => "You have a new subscriber to the {$newsletter->name} newsletter!"
        ]
    ]
]);
```

Using multiple webhooks
-----------------------

[](#using-multiple-webhooks)

You can also use an alternative webhook, by specify extra ones in the config file.

```
// in config/slack-alerts.php

'webhook_urls' => [
    'default' => 'https://hooks.slack.com/services/XXXXXX',
    'marketing' => 'https://hooks.slack.com/services/YYYYYY',
],
```

The webhook to be used can be chosen using the `to` function.

```
use Spatie\SlackAlerts\Facades\SlackAlert;

SlackAlert::to('marketing')->message("You have a new subscriber to the {$newsletter->name} newsletter!");
```

### Using a custom webhooks

[](#using-a-custom-webhooks)

The `to` function also supports custom webhook urls.

```
use Spatie\SlackAlerts\Facades\SlackAlert;

SlackAlert::to('https://custom-url.com')->message("You have a new subscriber to the {$newsletter->name} newsletter!");
```

### Sending message to an alternative channel

[](#sending-message-to-an-alternative-channel)

You can send a message to a channel other than the default one for the webhook, by passing it to the `toChannel` function.

```
use Spatie\SlackAlerts\Facades\SlackAlert;

SlackAlert::toChannel('subscription_alerts')->message("You have a new subscriber to the {$newsletter->name} newsletter!");
```

Queuing
-------

[](#queuing)

By default, messages are sent by dispatching the job to the `default` queue.

### Configuring the queue

[](#configuring-the-queue)

In `.env` file, add

```
SLACK_ALERT_QUEUE=queue_name
```

### Changing the queue at runtime

[](#changing-the-queue-at-runtime)

You can queue the job to a different queue than the one defined in config by passing it to the `onQueue` function.

```
use Spatie\SlackAlerts\Facades\SlackAlert;

SlackAlert::onQueue('some-queue')->message("Some message.");
```

Formatting
----------

[](#formatting)

### Markdown

[](#markdown)

You can format your messages with Slack's markup. Learn how [in the Slack API docs](https://slack.com/help/articles/202288908-Format-your-messages).

```
use Spatie\SlackAlerts\Facades\SlackAlert;

SlackAlert::message("A message *with some bold statements* and _some italicized text_.");
```

Links are formatted differently in Slack than the classic markdown structure.

```
SlackAlert::message("");
```

### Emoji's

[](#emojis)

You can use the same emoji codes as in Slack. This means custom emoji's are also supported.

```
use Spatie\SlackAlerts\Facades\SlackAlert;

SlackAlert::message(":smile: :custom-code:");
```

### Mentioning

[](#mentioning)

You can use mentions to notify users and groups. Learn how [in the Slack API docs](https://api.slack.com/reference/surfaces/formatting#mentioning-users).

```
use Spatie\SlackAlerts\Facades\SlackAlert;

SlackAlert::message("A message that notifies  and everyone else who is ")
```

### Icon Change

[](#icon-change)

You can change the icon that appears next to the display-name at the top of the message.

```
use Spatie\SlackAlerts\Facades\SlackAlert;

SlackAlert::withIconURL('https://example.com/tiny-icon.jpg')->message("Some message.");
```

### Display Name Change

[](#display-name-change)

You can change the Display-Name that appears next to the display-name at the top of the message.

```
use Spatie\SlackAlerts\Facades\SlackAlert;

SlackAlert::withUsername('More Descriptive Name')->message("Some message.");
```

### Synchronous Dispatch

[](#synchronous-dispatch)

By default, alerts are sent using jobs. Use the `sync()` method to send alerts synchronously, ensuring notifications are dispatched immediately before continuing execution:

```
use Spatie\SlackAlerts\Facades\SlackAlert;

// Send alert immediately
SlackAlert::sync()
    ->message("Some message.");
```

### Usage in tests

[](#usage-in-tests)

The package provides a `SlackAlertFake` that you can use to test your code without actually sending messages to Slack.

In your tests, you should call the `fake` method on the `SlackAlert` facade to start faking.

```
\Spatie\SlackAlerts\Facades\SlackAlert::fake();
```

These methods are available on the fake:

- `expectMessageSentContaining(string $expectedSubstring)`: Expects that at least one message contains the given substring
- `expectMessagesSent($callable = null)`: Expects that at least one message was sent. Optionally you can pass a callable that will get called for each message sent. Return true in one of the calls to make the expectation pass
- `expectNoMessagesSent()`: Expects that no messages were sent
- `expectNumberOfMessagesSent(int $expectedCount)`: Expects that exactly the given number of messages were sent
- `sentMessages()`: Returns all messages that were sent so you can pass the message to your own expectations

Alternatively, you can make use of the classic mocking approach.

```
// in a test

use Spatie\SlackAlerts\Facades\SlackAlert;

it('will send an alert to Slack', function() {

    SlackAlert::shouldReceive('message')->once();

    // execute code here that does send a message to Slack
});
```

Of course, you can also assert that a message wasn't sent to Slack.

```
// in a test

use Spatie\SlackAlerts\Facades\SlackAlert;

it('will not send an alert to Slack', function() {
    SlackAlert::shouldReceive('message')->never();

    // execute code here that doesn't send a message to Slack
});
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Niels Vanpachtenbeke](https://github.com/Nielsvanpach)
- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Alternatives
------------

[](#alternatives)

If you want to do more complex stuff with Block Kit, we suggest using [slack-php/slack-php-block-kit](https://github.com/slack-php/slack-php-block-kit)

###  Health Score

67

—

FairBetter than 100% of packages

Maintenance89

Actively maintained with recent releases

Popularity62

Solid adoption and visibility

Community31

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~69 days

Recently: every ~90 days

Total

23

Last Release

62d ago

Major Versions

0.0.4 → 1.0.02022-01-11

PHP version history (2 changes)0.0.1PHP ^8.0

1.6.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (91 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (47 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (26 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (17 commits)")[![mcpuishor](https://avatars.githubusercontent.com/u/40750444?v=4)](https://github.com/mcpuishor "mcpuishor (6 commits)")[![d2inco](https://avatars.githubusercontent.com/u/5826360?v=4)](https://github.com/d2inco "d2inco (4 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (4 commits)")[![riasvdv](https://avatars.githubusercontent.com/u/3626559?v=4)](https://github.com/riasvdv "riasvdv (4 commits)")[![miclf](https://avatars.githubusercontent.com/u/3188746?v=4)](https://github.com/miclf "miclf (2 commits)")[![AJenbo](https://avatars.githubusercontent.com/u/204594?v=4)](https://github.com/AJenbo "AJenbo (2 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (2 commits)")[![levu42](https://avatars.githubusercontent.com/u/1259689?v=4)](https://github.com/levu42 "levu42 (2 commits)")[![paulber33](https://avatars.githubusercontent.com/u/9802686?v=4)](https://github.com/paulber33 "paulber33 (2 commits)")[![projecthanif](https://avatars.githubusercontent.com/u/121246102?v=4)](https://github.com/projecthanif "projecthanif (2 commits)")[![ReinisL](https://avatars.githubusercontent.com/u/18574406?v=4)](https://github.com/ReinisL "ReinisL (2 commits)")[![tominon](https://avatars.githubusercontent.com/u/508519?v=4)](https://github.com/tominon "tominon (1 commits)")[![vzhabonos](https://avatars.githubusercontent.com/u/16108509?v=4)](https://github.com/vzhabonos "vzhabonos (1 commits)")[![mikkellindblom](https://avatars.githubusercontent.com/u/5261690?v=4)](https://github.com/mikkellindblom "mikkellindblom (1 commits)")[![bogdan-lopatkin](https://avatars.githubusercontent.com/u/52372518?v=4)](https://github.com/bogdan-lopatkin "bogdan-lopatkin (1 commits)")[![phil-hudson](https://avatars.githubusercontent.com/u/1914950?v=4)](https://github.com/phil-hudson "phil-hudson (1 commits)")

---

Tags

laravelloggingphpslackspatielaravellaravel-slack-alerts

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/spatie-laravel-slack-alerts/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-laravel-slack-alerts/health.svg)](https://phpackages.com/packages/spatie-laravel-slack-alerts)
```

###  Alternatives

[spatie/laravel-activitylog

A very simple activity logger to monitor the users of your website or application

5.8k45.4M309](/packages/spatie-laravel-activitylog)[spatie/laravel-health

Monitor the health of a Laravel application

86910.0M83](/packages/spatie-laravel-health)[spatie/laravel-data

Create unified resources and data transfer objects

1.8k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-error-share

Share your Laravel errors to Flare

43965.6k3](/packages/spatie-laravel-error-share)[spatie/laravel-prometheus

Export Laravel metrics to Prometheus

2651.3M6](/packages/spatie-laravel-prometheus)[keepsuit/laravel-opentelemetry

OpenTelemetry integration for laravel

142347.8k](/packages/keepsuit-laravel-opentelemetry)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
