https://github.com/invokable/laravel-notification-discord-webhook
https://github.com/invokable/laravel-notification-discord-webhook
discord
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/invokable/laravel-notification-discord-webhook
- Owner: invokable
- License: mit
- Created: 2024-03-27T03:42:52.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-21T10:07:25.000Z (11 months ago)
- Last Synced: 2025-07-22T10:38:10.101Z (10 months ago)
- Topics: discord
- Language: PHP
- Homepage: https://packagist.org/packages/revolution/laravel-notification-discord-webhook
- Size: 64.5 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Notification for Discord(Webhook)
[](https://qlty.sh/gh/invokable/projects/laravel-notification-discord-webhook)
[](https://qlty.sh/gh/invokable/projects/laravel-notification-discord-webhook)
## Introduction
This package allows you to easily send notifications to Discord by simply specifying a webhook. With this Laravel notification channel, you can quickly integrate Discord notifications into your application without dealing with the complexities of Discord's API. Just configure your webhook URL and start sending notifications right away.
https://discord.com/developers/docs/resources/webhook#execute-webhook
## Requirements
- PHP >= 8.2
- Laravel >= 11.0
## Installation
```shell
composer require revolution/laravel-notification-discord-webhook
```
### Uninstall
```shell
composer remove revolution/laravel-notification-discord-webhook
```
## Config
Get the webhook url from your Discord server settings.
https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
### config/services.php
```php
'discord' => [
'webhook' => env('DISCORD_WEBHOOK'),
],
```
### .env
```
DISCORD_WEBHOOK=https://discord.com/api/webhooks/...
```
## Usage
```php
content);
}
}
```
### On-Demand Notification
```php
use Illuminate\Support\Facades\Notification;
Notification::route('discord-webhook', config('services.discord.webhook'))
->notify(new DiscordNotification('test'));
```
### User Notification
```php
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use Notifiable;
public function routeNotificationForDiscordWebhook($notification): string
{
return $this->discord_webhook;
}
}
```
```php
$user->notify(new DiscordNotification('test'));
```
### Send embeds
```php
use Revolution\Laravel\Notification\DiscordWebhook\DiscordMessage;
use Revolution\Laravel\Notification\DiscordWebhook\DiscordEmbed;
public function toDiscordWebhook(object $notifiable): DiscordMessage
{
return DiscordMessage::create()
->embed(
DiscordEmbed::make(
title: 'INFO',
description: $this->content,
url: route('home'),
)
);
}
```
### Send attachment files
Send only file. `content` and `filename` are required.
```php
use Revolution\Laravel\Notification\DiscordWebhook\DiscordMessage;
use Revolution\Laravel\Notification\DiscordWebhook\DiscordAttachment;
use Illuminate\Support\Facades\Storage;
public function toDiscordWebhook(object $notifiable): DiscordMessage
{
return DiscordMessage::create()
->file(
DiscordAttachment::make(
content: Storage::get('test.png'),
filename: 'test.png',
description: 'test',
filetype: 'image/png'
));
}
```
Using files in embed.
```php
use Revolution\Laravel\Notification\DiscordWebhook\DiscordMessage;
use Revolution\Laravel\Notification\DiscordWebhook\DiscordAttachment;
use Revolution\Laravel\Notification\DiscordWebhook\DiscordEmbed;
use Illuminate\Support\Facades\Storage;
public function toDiscordWebhook(object $notifiable): DiscordMessage
{
return DiscordMessage::create()
->embed(
DiscordEmbed::make(
title: 'test',
description: $this->content,
image: 'attachment://test.jpg',
thumbnail: 'attachment://test2.jpg',
)
);
->file(DiscordAttachment::make(
content: Storage::get('test.jpg'),
filename: 'test.jpg',
description: 'test',
filetype: 'image/jpg'
))
->file(new DiscordAttachment(
content: Storage::get('test2.jpg'),
filename: 'test2.jpg',
description: 'test2',
filetype: 'image/jpg'
));
}
```
### Send any message
```php
public function toDiscordWebhook(object $notifiable): DiscordMessage
{
return DiscordMessage::create()
->with([
'content' => $this->content,
'embeds' => [[]],
]);
}
```
## LICENSE
MIT