Update 'README.md'

This commit is contained in:
Maxime 2020-05-07 15:37:48 +02:00
parent b2fcefb7ec
commit 2f2074b904
1 changed files with 32 additions and 51 deletions

View File

@ -1,117 +1,98 @@
# 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
First in your composer.json, add :
First in your composer.json, add:
```bash
```
"require": {
"bluescale/laravel-bmail": "dev-master"
}
```
and
```bash
```
"repositories": [
{
"type": "vcs",
"url": "git@git.bluesquare.io:bluescale/laravel-bmail.git"
"url": "https://git.bluesquare.io/bluescale/laravel-bmail"
}
]
```
Next update your package :
Next update your package:
```bash
composer update bluescale/laravel-bmail
```
Then publish the assets from your provider :
Then publish the assets from your provider:
```bash
php artisan vendor:publish
```
Finally get your API key :
```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 :
Finally, copy your API key from Bluescale Mail (Templates section), and add it in your `.env`:
```bash
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
```
## Usage
First, create a new notification or use an existing one :
First, create a new notification or use an existing one:
```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
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
```php
return [BMailChannel::class];
```
Then, create a 'toTemplate()' method, in which you specify your template fields :
```bash
```php
public function toTemplate($notifiable)
{
return (new BMailTemplate($this->template_id))
->sender("john.doe@gmail.com", "John OPTIONNAL") OPTIONNAL
->replyTo("jean.grey@gmail.com", "Jean OPTIONNAL") OPTIONNAL
return (new BMailTemplate("my-template-id"))
->sender("john.doe@gmail.com", "John OPTIONAL") // OPTIONAL
->replyTo("jean.grey@gmail.com", "Jean OPTIONAL") // OPTIONAL
->recipients([
[
"elvis@gmail.com", [
"name" => "Elvis" OPTIONNAL,
"parameters" => ["key" => "value"] OPTIONNAL
"name" => "Elvis" // OPTIONAL,
"parameters" => ["key" => "value"] // OPTIONAL
]
],
[
"robert@gmail.com"
]
])
->addRecipient("edward@gmail.com")
->parameters(["key" => "value", "key" => "value"])
->addParameter("key", "value");
->addRecipient("edward@gmail.com") // OPTIONAL
->parameters(["key" => "value", "key" => "value"]) // OPTIONAL
->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
User::find('user_id')->notify(new BMailNotification('template_id'));
```php
User::first()->notify(new MyAwesomeNotification);
```