Constructor changing type hint

This commit is contained in:
Loann 2020-04-28 18:07:20 +02:00
parent f1da79c869
commit f29b5a8854
2 changed files with 16 additions and 9 deletions

View File

@ -56,17 +56,18 @@ First, create a new notification or use an existing one :
php artisan make:notification BMailNotification php artisan make:notification BMailNotification
``` ```
Next, add a public field '$id' to your class, which will be initialized in the constructor : Next, add a public field '$template_id' to your class, which will be initialized in the constructor :
```bash ```bash
public $id; public $template_id;
/** /**
* @param Integer $id * BMailNotification constructor.
* @param string $template_id
*/ */
public function __construct(Integer $id) public function __construct(string $template_id)
{ {
$this->id = $id; $this->template_id = $template_id;
} }
``` ```
@ -81,7 +82,7 @@ Then, create a 'toTemplate()' method, in which you specify your template fields
```bash ```bash
public function toTemplate($notifiable) public function toTemplate($notifiable)
{ {
return (new BMailTemplate($this->id)) return (new BMailTemplate($this->template_id))
->sender("john.doe@gmail.com", "John OPTIONNAL") OPTIONNAL ->sender("john.doe@gmail.com", "John OPTIONNAL") OPTIONNAL
->replyTo("jean.grey@gmail.com", "Jean OPTIONNAL") OPTIONNAL ->replyTo("jean.grey@gmail.com", "Jean OPTIONNAL") OPTIONNAL
->recipients([ ->recipients([
@ -101,7 +102,13 @@ public function toTemplate($notifiable)
} }
``` ```
Finally, from your controller, send a notification for a user : Finally, get the template's id :
```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 :
```bash ```bash
User::find('user_id')->notify(new BMailNotification('template_id')); User::find('user_id')->notify(new BMailNotification('template_id'));

View File

@ -7,7 +7,7 @@ class BMailTemplate implements \JsonSerializable
/** /**
* The template for the message * The template for the message
* *
* @var integer * @var string
*/ */
public $template; public $template;
@ -39,7 +39,7 @@ class BMailTemplate implements \JsonSerializable
*/ */
public $parameters = []; public $parameters = [];
public function __construct(int $template) public function __construct(string $template)
{ {
$this->template = $template; $this->template = $template;
} }