konstruktiv/laravel-sendgrid-notification-channel

v1.0.3 2022-01-18 12:05 UTC

This package is auto-updated.

Last update: 2024-09-29 05:50:04 UTC


README

Laravel Sendgrid通知通道

安装

要开始使用,您需要要求此包

composer require konstruktiv/laravel-sendgrid-notification-channel

Laravel将自动检测服务提供者。因此,无需手动注册。

使用方法

要使用此包,您的通知类应如下所示

<?php

namespace App\Notifications;

use Illuminate\Notifications\Notification;

class ExampleNotification extends Notification
{
    public function via($notifiable)
    {
        return [
            'sendgrid',
            // And any other channels you want can go here...
        ];
    }
    
    /**
     * Get the SendGrid representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return SendGridMessage
     */
    public function toSendGrid(mixed $notifiable): SendGridMessage
    {
        return (new SendGridMessage('Your SendGrid template ID'))
            ->subject('Subject goes here')
            ->from('sendgrid@example.com','SendGrid')
            ->to(
                $notifiable->email,
                $notifiable->name
            )
            ->payload([
                'key' => 'value'
            ]);
	}
}