Skip to content

Commit d42522e

Browse files
authored
Update README.md
1 parent 0803d2d commit d42522e

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

README.md

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ To get started, you need to require this package:
2929
composer require swiftmade/laravel-sendgrid-notification-channel
3030
```
3131

32+
The service provider will be auto-detected by Laravel. So, no need to register it manually.
33+
3234
Next, make sure you have a valid sendgrid api key at `config/services.php`. You may copy the example configuration below to get started:
3335

3436
```php
@@ -39,26 +41,43 @@ Next, make sure you have a valid sendgrid api key at `config/services.php`. You
3941

4042
## Usage
4143

42-
You should add a `toSendGrid` method into the notification class. This method will receive a `$notifiable` entity and should return a `NotificationChannels\SendGrid\SendGridMessage` instance:
44+
To make use of this package, your notification class should look like this:
4345

4446
```php
45-
/**
46-
* Get the SendGrid representation of the notification.
47-
*
48-
* @param mixed $notifiable
49-
* @return \NotificationChannels\SendGrid\SendGridMessage
50-
*/
47+
<?php
48+
49+
namespace App\Notifications;
50+
51+
use Illuminate\Notifications\Notification;
52+
53+
class ExampleNotification extends Notification
54+
{
55+
public function via($notifiable)
56+
{
57+
return [
58+
\NotificationChannels\SendGrid\SendGridChannel::class,
59+
// And any other channels you want can go here...
60+
];
61+
}
62+
63+
// ...
64+
5165
public function toSendGrid($notifiable)
5266
{
5367
return (new SendGridMessage('Your SendGrid template ID'))
54-
->payload([
55-
"template_var_1" => "template_value_1"
56-
])
57-
->from('test@example.com', 'Example User')
58-
->to('test+test1@example.com', 'Example User1');
68+
->payload([
69+
"template_var_1" => "template_value_1"
70+
]);
5971
}
72+
}
73+
6074
```
6175

76+
`toSendGrid` method will receive a `$notifiable` entity and should return a `NotificationChannels\SendGrid\SendGridMessage` instance.
77+
78+
💡 Unless you set them explicitly, **From** address will be `config('mail.from.address')` and the **To** value will be what returns from `$notifiable->routeNotificationFor('mail');`
79+
80+
6281
## Changelog
6382

6483
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

0 commit comments

Comments
 (0)