Search code examples
laravelpush-notificationnotificationsslackslack-api

Notify everyone in a Slack channel via Laravel


I'm using Laravel Notifications functionality to post from our app to a Slack channel.

It works as I'd expect but would like this particular piece of functionality to '@channel' so that it pushes a notification to our users who have the Slack mobile app.

return (new SlackMessage)
        ->success()
        ->content("A ride request has been raised")
        ->attachment(function ($attachment) use ($ride) {
            $attachment->title($ride->name, route('ride', $ride->id))
                ->content($ride->pickup_address);
        });

I have tried changing the to method without any joy.


Solution

  • While you can customise the to method, that's not how it's done.

    Instead you want to add the <!channel> keyword into your content() method like this:

    ->content("Hey <!channel> someone has done something")

    Simple stuff.