PHP code example of snoeren-development / laravel-discord-webhook-channel

1. Go to this page and download the library: Download snoeren-development/laravel-discord-webhook-channel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

snoeren-development / laravel-discord-webhook-channel example snippets


use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class User extends Model
{
    use Notifiable;

    /**
     * Route the notification for Discord.
     *
     * @return string
     */
    public function routeNotificationForDiscord(): string
    {
        return $this->discord_webhook;
    }
}

use SnoerenDevelopment\DiscordWebhook\DiscordMessage;
use SnoerenDevelopment\DiscordWebhook\DiscordWebhookChannel;

class DiscordNotification extends Notification
{
    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed $notifiable The notifiable model.
     * @return array
     */
    public function via($notifiable)
    {
        return [DiscordWebhookChannel::class];
    }

    /**
     * Get the Discord representation of the notification.
     *
     * @param  mixed $notifiable The notifiable model.
     * @return \SnoerenDevelopment\DiscordWebhook\DiscordMessage
     */
    public function toDiscord($notifiable): DiscordMessage
    {
        return DiscordMessage::create()
            ->username('My Laravel App')
            ->content('The message body.')
            ->avatar('https://domain.com/avatar.jpg')
            ->tts(false);
    }
}