PHP code example of jlorente / laravel-sendgrid

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

    

jlorente / laravel-sendgrid example snippets


return [
    //other stuff
    'providers' => [
        //other stuff
        \Jlorente\Laravel\SendGrid\SendGridServiceProvider::class,
    ];
];

return [
    //other stuff
    'aliases' => [
        //other stuff
        'SendGrid' => \Jlorente\Laravel\SendGrid\Facades\SendGrid::class,
    ];
];

return [
    'api_key' => 'YOUR_API_KEY',
    //other configuration
];

SendGrid::send($mail);

/**
 * Get the Mail object instance.
 *
 * @param  mixed  $notifiable
 * @return \SendGrid\Mail\Mail
 */
public function toSendGrid($notifiable)
{
    $mail = new \SendGrid\Mail\Mail();
    $mail->setFrom();
    $mail->setTemplateId('d-4n23blaasjdgdg3242');
    $mail->addDynamicTemplateData('username', 'John');

    return $mail;
}

/**
 * Get the notification channels.
 *
 * @param  mixed  $notifiable
 * @return array|string
 */
public function via($notifiable)
{
    return [SendGridEmailChannel::class];
}



namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * Route notifications for the SendGrid SMS channel.
     *
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return string
     */
    public function routeNotificationForSendGrid($notification)
    {
        return $this->email;
    }
}
bash
$ php composer.phar 
bash
$ php artisan vendor:publish --provider='Jlorente\Laravel\SendGrid\SendGridServiceProvider'