Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mehalubozo's avatar

Laravel slack webhook, multiple channels

Hi,

Looking in the documentation of Laravel I can use notifications with Slack. There seems to be an option to call ->to(‘#channel’)t this doesn't work when you create a new webhook URL. The webhook URL only has access to one channel at a time.

How can I make this work?

0 likes
3 replies
fylzero's avatar

@mehalubozo This should work....

public function toSlack($notifiable)
{
    return (new SlackMessage)
                ->from('Ghost', ':ghost:')
                ->to('#other')
                ->content('This will be sent to #other');
}

Have you actually tried using the web hook? Reason I ask... I know Slack asks you to choose a channel... but it shouldn't matter. I've created webhooks that fire to any channel.

It's something I've also found incredibly confusing.

1 like
bobbybouwmann's avatar
Level 88

Yes, you’re correct. Slack recently made some changes to this. Slack offers two options. Either a webhook URL which is connected to a specific channel or a Slack bot which has access to all channels. If you want to write to multiple channels you either need to set up a bot or configure the URL per channel.

For a notification that doesn’t belong to a user, you get something like this

Notification::route('slack', ‘https://hooks.slack.com/services/12345’)
    ->notify(new NewSale();

Another alternative is setting the URL per user. You can do that on the User model by doing this

// User.php

public function routeNotificationForSlack($notification)
{
    return ‘https://hooks.slack.com/services/12345’;
}
mehalubozo's avatar

@fylzero I can only post to one channel with the webhook. It only posts to one channel now. You need to create a webhook per channel now.

@bobbybouwmann Thanks! Works perfectly with multiple urls. I'm also going to look at the bot implementation

Please or to participate in this conversation.