Update 'README.md'
This commit is contained in:
parent
b2fcefb7ec
commit
2f2074b904
75
README.md
75
README.md
|
@ -1,24 +1,23 @@
|
||||||
# BMail
|
# laravel-bmail
|
||||||
|
|
||||||
The BMail package allows you to send email templates with Laravel to the Bluescale API.
|
The Bluescale Mail package allows you to send Bluescale Mail templates using Laravel notifications system.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
First in your composer.json, add:
|
First in your composer.json, add:
|
||||||
|
|
||||||
```bash
|
```
|
||||||
"require": {
|
"require": {
|
||||||
"bluescale/laravel-bmail": "dev-master"
|
"bluescale/laravel-bmail": "dev-master"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
and
|
|
||||||
|
|
||||||
```bash
|
```
|
||||||
"repositories": [
|
"repositories": [
|
||||||
{
|
{
|
||||||
"type": "vcs",
|
"type": "vcs",
|
||||||
"url": "git@git.bluesquare.io:bluescale/laravel-bmail.git"
|
"url": "https://git.bluesquare.io/bluescale/laravel-bmail"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
@ -35,16 +34,15 @@ Then publish the assets from your provider :
|
||||||
php artisan vendor:publish
|
php artisan vendor:publish
|
||||||
```
|
```
|
||||||
|
|
||||||
Finally get your API key :
|
Finally, copy your API key from Bluescale Mail (Templates section), and add it in your `.env`:
|
||||||
|
|
||||||
```bash
|
|
||||||
Connect to https://bluescale.email, go to the Templates tab, click on the API button and copy your API key.
|
|
||||||
```
|
|
||||||
|
|
||||||
And add it in your .env, along with the API URL :
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
BMAIL_API_KEY=your_api_key
|
BMAIL_API_KEY=your_api_key
|
||||||
|
```
|
||||||
|
|
||||||
|
You may also want to use your own API:
|
||||||
|
|
||||||
|
```bash
|
||||||
BMAIL_API_URL=https://bluescale.email/api/project/template/send
|
BMAIL_API_URL=https://bluescale.email/api/project/template/send
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -53,65 +51,48 @@ BMAIL_API_URL=https://bluescale.email/api/project/template/send
|
||||||
First, create a new notification or use an existing one:
|
First, create a new notification or use an existing one:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
php artisan make:notification BMailNotification
|
php artisan make:notification MyAwesomeNotification
|
||||||
```
|
```
|
||||||
|
|
||||||
Next, add a public field '$template_id' to your class, which will be initialized in the constructor :
|
Add BMailChannel in the `via()` method:
|
||||||
|
|
||||||
```bash
|
```php
|
||||||
public $template_id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BMailNotification constructor.
|
|
||||||
* @param string $template_id
|
|
||||||
*/
|
|
||||||
public function __construct(string $template_id)
|
|
||||||
{
|
|
||||||
$this->template_id = $template_id;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Then, in the via method add :
|
|
||||||
|
|
||||||
```bash
|
|
||||||
return [BMailChannel::class];
|
return [BMailChannel::class];
|
||||||
```
|
```
|
||||||
|
|
||||||
Then, create a 'toTemplate()' method, in which you specify your template fields :
|
Then, create a 'toTemplate()' method, in which you specify your template fields :
|
||||||
|
|
||||||
```bash
|
```php
|
||||||
public function toTemplate($notifiable)
|
public function toTemplate($notifiable)
|
||||||
{
|
{
|
||||||
return (new BMailTemplate($this->template_id))
|
return (new BMailTemplate("my-template-id"))
|
||||||
->sender("john.doe@gmail.com", "John OPTIONNAL") OPTIONNAL
|
->sender("john.doe@gmail.com", "John OPTIONAL") // OPTIONAL
|
||||||
->replyTo("jean.grey@gmail.com", "Jean OPTIONNAL") OPTIONNAL
|
->replyTo("jean.grey@gmail.com", "Jean OPTIONAL") // OPTIONAL
|
||||||
->recipients([
|
->recipients([
|
||||||
[
|
[
|
||||||
"elvis@gmail.com", [
|
"elvis@gmail.com", [
|
||||||
"name" => "Elvis" OPTIONNAL,
|
"name" => "Elvis" // OPTIONAL,
|
||||||
"parameters" => ["key" => "value"] OPTIONNAL
|
"parameters" => ["key" => "value"] // OPTIONAL
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"robert@gmail.com"
|
"robert@gmail.com"
|
||||||
]
|
]
|
||||||
])
|
])
|
||||||
->addRecipient("edward@gmail.com")
|
->addRecipient("edward@gmail.com") // OPTIONAL
|
||||||
->parameters(["key" => "value", "key" => "value"])
|
->parameters(["key" => "value", "key" => "value"]) // OPTIONAL
|
||||||
->addParameter("key", "value");
|
->addParameter("key", "value") // OPTIONAL
|
||||||
|
;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Finally, get the template's id :
|
The $notifiable is automaticaly added as recipient.
|
||||||
|
|
||||||
```bash
|
|
||||||
Go to https://bluescale.email, Templates tab, click on the template you want to use and copy the template identifier.
|
|
||||||
```
|
|
||||||
|
|
||||||
And from your controller, send a notification for a user :
|
In your controller, you can now send your template:
|
||||||
|
|
||||||
```bash
|
```php
|
||||||
User::find('user_id')->notify(new BMailNotification('template_id'));
|
User::first()->notify(new MyAwesomeNotification);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue