konstruktiv/laravel-sendgrid-notification-channel

Our Laravel Sendgrid Notification package

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

This package is auto-updated.

Last update: 2024-04-29 04:45:57 UTC


README

Laravel Sendgrid Notification channel

Installation

To get started, you need to require this package:

composer require konstruktiv/laravel-sendgrid-notification-channel

The service provider will be auto-detected by Laravel. So, no need to register it manually.

Usage

To make use of this package, your notification class should look like this:

<?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'
            ]);
	}
}