What is Discord ?
Discord is a video/audio calling VoIP application. Discord is free and created for video game communities.
It does not only provide audio or video chat feature but also specialises in text and image in chat channels.
In discord you can make various servers containing particular channels for different tasks ie. for playing different games with your squad or listening music or join afk channels of a server if you are simply AFK.
Features of Laravel Discord Notification Channel
- Laravel discord notification channel support slack payload by using (new SlackMessage) or $this->toSlack($notifiable).
- It also support discord webhook payload.
- It is very easy to use.
How to install ?
Installation of this package is very easy. What you need to do is to follow this simple command:
1 |
composer require awssat/discord-notification-channel |
How to use it now ?
One must define the discord method in the notification channel.
1 2 3 4 |
public function via($notifiable) { return ['mail', 'discord']; } |
Now, create a toDiscord() method
1 2 3 4 5 6 7 8 9 10 11 |
public function toDiscord($notifiable) { return (new DiscordMessage) ->from('Laravel') ->content('Content') ->embed(function ($embed) { $embed->title('Discord is cool')->description('Slack nah') ->field('Laravel', '7.0.0', true) ->field('PHP', '8.0.0', true); }); } |
Route discord notifications
To route Discord notifications to the proper location, define a routeNotificationForDiscord method on your notifiable entity.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
class User extends Authenticatable { use Notifiable; /** * Route notifications for the Discord channel. * * @param \Illuminate\Notifications\Notification $notification * @return string */ public function routeNotificationForDiscord($notification) { return 'https://discordapp.com/api/webhooks/.......'; } } |
That’s it, you are done now. You can send the notification to the discord channels from your laravel application.
Source: Github of Laravel discord notification channel Git repository