laravel-mail/README.md

99 lines
2.0 KiB
Markdown
Raw Normal View History

2020-05-07 15:37:48 +02:00
# laravel-bmail
2020-05-07 15:37:48 +02:00
The Bluescale Mail package allows you to send Bluescale Mail templates using Laravel notifications system.
2020-04-09 17:57:21 +02:00
## Installation
2020-05-07 15:37:48 +02:00
First in your composer.json, add:
2020-05-07 15:37:48 +02:00
```
2020-04-09 16:00:19 +02:00
"require": {
"bluescale/laravel-bmail": "dev-master"
2020-04-10 13:11:40 +02:00
}
2020-04-09 17:29:07 +02:00
```
2020-04-09 16:00:19 +02:00
2020-05-07 15:37:48 +02:00
```
2020-04-09 16:00:19 +02:00
"repositories": [
{
"type": "vcs",
2020-05-07 15:37:48 +02:00
"url": "https://git.bluesquare.io/bluescale/laravel-bmail"
2020-04-09 16:00:19 +02:00
}
2020-04-10 13:11:40 +02:00
]
2020-04-09 16:00:19 +02:00
```
2020-05-07 15:37:48 +02:00
Next update your package:
2020-04-09 16:00:19 +02:00
```bash
2020-04-09 17:43:19 +02:00
composer update bluescale/laravel-bmail
```
2020-04-09 17:21:16 +02:00
2020-05-07 15:37:48 +02:00
Then publish the assets from your provider:
2020-04-09 17:21:16 +02:00
```bash
php artisan vendor:publish
```
2020-05-07 15:37:48 +02:00
Finally, copy your API key from Bluescale Mail (Templates section), and add it in your `.env`:
2020-04-09 17:43:19 +02:00
```bash
2020-05-07 15:37:48 +02:00
BMAIL_API_KEY=your_api_key
```
2020-05-07 15:37:48 +02:00
You may also want to use your own API:
```bash
BMAIL_API_URL=https://bluescale.email/api/project/template/send
2020-04-09 17:43:19 +02:00
```
2020-04-09 17:57:21 +02:00
## Usage
2020-05-07 15:37:48 +02:00
First, create a new notification or use an existing one:
2020-04-14 18:26:08 +02:00
```bash
2020-05-07 15:37:48 +02:00
php artisan make:notification MyAwesomeNotification
2020-04-14 18:26:08 +02:00
```
2020-05-07 15:37:48 +02:00
Add BMailChannel in the `via()` method:
2020-04-14 18:26:08 +02:00
2020-05-07 15:37:48 +02:00
```php
2020-04-14 18:26:08 +02:00
return [BMailChannel::class];
```
2020-04-14 18:29:13 +02:00
Then, create a 'toTemplate()' method, in which you specify your template fields :
2020-04-14 18:26:08 +02:00
2020-05-07 15:37:48 +02:00
```php
2020-04-14 18:26:08 +02:00
public function toTemplate($notifiable)
{
2020-05-07 15:37:48 +02:00
return (new BMailTemplate("my-template-id"))
->sender("john.doe@gmail.com", "John OPTIONAL") // OPTIONAL
->replyTo("jean.grey@gmail.com", "Jean OPTIONAL") // OPTIONAL
2020-04-14 18:26:08 +02:00
->recipients([
[
"elvis@gmail.com", [
2020-05-07 15:37:48 +02:00
"name" => "Elvis" // OPTIONAL,
"parameters" => ["key" => "value"] // OPTIONAL
2020-04-14 18:26:08 +02:00
]
],
[
"robert@gmail.com"
2020-04-10 13:10:48 +02:00
]
2020-04-14 18:26:08 +02:00
])
2020-05-07 15:37:48 +02:00
->addRecipient("edward@gmail.com") // OPTIONAL
->parameters(["key" => "value", "key" => "value"]) // OPTIONAL
->addParameter("key", "value") // OPTIONAL
;
2020-04-14 18:26:08 +02:00
}
2020-04-09 17:57:21 +02:00
```
2020-05-07 15:37:48 +02:00
The $notifiable is automaticaly added as recipient.
2020-04-28 18:07:20 +02:00
2020-05-07 15:37:48 +02:00
In your controller, you can now send your template:
2020-04-14 18:26:08 +02:00
2020-05-07 15:37:48 +02:00
```php
User::first()->notify(new MyAwesomeNotification);
2020-04-09 17:57:21 +02:00
```
2020-04-09 17:21:16 +02:00