PHP code example of konstruktiv / laravel-sendgrid-notification-channel

1. Go to this page and download the library: Download konstruktiv/laravel-sendgrid-notification-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/ */

    

konstruktiv / laravel-sendgrid-notification-channel example snippets




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('[email protected]','SendGrid')
            ->to(
                $notifiable->email,
                $notifiable->name
            )
            ->payload([
                'key' => 'value'
            ]);
	}
}