laravel-mail/README.md

105 lines
1.9 KiB
Markdown
Raw Normal View History

# BMail
2020-04-14 18:26:08 +02:00
The BMail package allows you to send email templates with Laravel to the Bluescale API.
2020-04-09 17:57:21 +02:00
## Installation
2020-04-09 17:43:19 +02:00
First in your composer.json, add :
```bash
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
and
```bash
"repositories": [
{
"type": "vcs",
"url": "git@git.bluesquare.io:bluescale/laravel-bmail.git"
}
2020-04-10 13:11:40 +02:00
]
2020-04-09 16:00:19 +02:00
```
2020-04-09 17:43:19 +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-04-09 17:43:19 +02:00
Then publish the assets from your provider :
2020-04-09 17:21:16 +02:00
```bash
php artisan vendor:publish
```
2020-04-09 17:43:19 +02:00
Finally add your API key in the .env :
```bash
BMAIL_API_KEY=your_key
BMAIL_API_URL=the_api_url
```
2020-04-09 17:57:21 +02:00
## Usage
2020-04-14 18:26:08 +02:00
First, create a new notification or use an existing one :
```bash
php artisan make:notification BMailNotification
```
2020-04-14 18:29:13 +02:00
Next, add a public field '$id' to your class, which will be initialized in the constructor :
2020-04-14 18:26:08 +02:00
```bash
public $id;
/**
* @param Integer $id
*/
public function __construct(Integer $id)
{
$this->id = $id;
}
```
Then, in the via method add :
```bash
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-04-09 17:57:21 +02:00
```bash
2020-04-14 18:26:08 +02:00
public function toTemplate($notifiable)
{
return (new BMailTemplate($this->id))
->sender("john.doe@gmail.com", "John OPTIONNAL") OPTIONNAL
->replyTo("jean.grey@gmail.com", "Jean OPTIONNAL") OPTIONNAL
->recipients([
[
"elvis@gmail.com", [
"name" => "Elvis" OPTIONNAL,
"parameters" => ["key" => "value"] OPTIONNAL
]
],
[
"robert@gmail.com"
2020-04-10 13:10:48 +02:00
]
2020-04-14 18:26:08 +02:00
])
->addRecipient("edward@gmail.com")
->parameters(["key" => "value", "key" => "value"])
->addParameter("key", "value");
}
2020-04-09 17:57:21 +02:00
```
2020-04-14 18:32:47 +02:00
Finally, from your controller, send a notification for a user :
2020-04-14 18:26:08 +02:00
2020-04-09 17:57:21 +02:00
```bash
2020-04-14 18:26:08 +02:00
User::find('user_id')->notify(new BMailNotification('template_id'));
2020-04-09 17:57:21 +02:00
```
2020-04-09 17:21:16 +02:00