Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.5 On demand notification with slack

According to this page, we can send a notification on demand without going through a model. How do I do the same using slack?

I want to do something like this:

$emailAddress = 'my email address';
Notification::route('mail', $emailAddress)
            ->route('slack', 'what do I put here?')
            ->notify(new TestNotification());

The code works without the slack line.

Edit: this StackOverflow question uses the on demand method

like image 488
Edwin Avatar asked Jan 16 '18 09:01

Edwin


People also ask

How to send slack notifications from Laravel application?

Before you can start sending Slack notifications from your Laravel application we’ll need to install the Slack notification channel package: You’ll also need to install the “ Incoming Webhooks ” app in your Slack workspace. By doing so, you’ll be able to generate a unique URL which will be used to send messages to a designated Slack channel.

What is the broadcast channel in Laravel?

The broadcast channel broadcasts notifications using Laravel's event broadcasting services, allowing your JavaScript powered frontend to catch notifications in realtime. If a notification supports broadcasting, you can define a toBroadcast method on the notification class.

Does Laravel support email notifications?

In addition to support for sending email, Laravel provides support for sending notifications across a variety of delivery channels, including email, SMS (via Vonage, formerly known as Nexmo), and Slack. In addition, a variety of community built notification channels have been created to send notifications over dozens of different channels!

How to listen for notifications on a channel in Laravel Echo?

When using Laravel Echo, you may easily listen for notifications on a channel using the notification method: If you would like to customize which channel that an entity's broadcast notifications are broadcast on, you may define a receivesBroadcastNotificationsOn method on the notifiable entity:


1 Answers

You should you put the Slack Webhook URL. See: https://laravel.com/docs/5.5/notifications#routing-slack-notifications

 Notification::route('slack', 'https://hooks.slack.com/services/ZZZZ/YYYY/XXX')->notify(new DailyStats());
like image 195
FooBar Avatar answered Oct 09 '22 15:10

FooBar