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
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.
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.
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!
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:
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With