Skip to content

Commit b674c73

Browse files
authored
Update README.md
1 parent 3fd3121 commit b674c73

File tree

1 file changed

+70
-70
lines changed

1 file changed

+70
-70
lines changed

README.md

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -28,79 +28,13 @@ Publish config: `a vendor:publish --tag=mailator-config`
2828

2929
It has mainly 2 directions of usage:
3030

31-
1. Email Templates & Placeholders
31+
1. Schedule emails sending (or actions triggering)
3232

33-
2. Email Scheduler
34-
35-
## Templating
36-
37-
To create an email template:
38-
39-
``` php
40-
$template = Binarcode\LaravelMailator\Models\MailTemplate::create([
41-
'name' => 'Welcome Email.',
42-
'from_email' => 'from@bar.com',
43-
'from_name' => 'From Bar',
44-
'subject' => 'Welcome to Mailator.',
45-
'html' => '<h1>Welcome to the party!</h1>',
46-
]);
47-
```
48-
49-
Adding some placeholders with description to this template:
50-
51-
```php
52-
$template->placeholders()->create(
53-
[
54-
'name' => '::name::',
55-
'description' => 'Name',
56-
],
57-
);
58-
```
59-
60-
To use the template, you simply have to add the `WithMailTemplate` trait to your mailable.
61-
62-
This will enforce you to implement the `getReplacers` method, this should return an array of replacers to your template.
63-
The array may contain instances of `Binarcode\LaravelMailator\Replacers\Replacer` or even `Closure` instances.
64-
65-
Mailator shipes with a builtin replacer `ModelAttributesReplacer`, it will automaticaly replace attributes from the
66-
model you provide to placeholders.
67-
68-
The last step is how to say to your mailable what template to use. This could be done into the build method as shown
69-
bellow:
70-
71-
```php
72-
class WelcomeMailatorMailable extends Mailable
73-
{
74-
use Binarcode\LaravelMailator\Support\WithMailTemplate;
75-
76-
private Model $user;
77-
78-
public function __construct(Model $user)
79-
{
80-
$this->user = $user;
81-
}
82-
83-
public function build()
84-
{
85-
return $this->template(MailTemplate::firstWhere('name', 'Welcome Email.'));
86-
}
87-
88-
public function getReplacers(): array
89-
{
90-
return [
91-
Binarcode\LaravelMailator\Replacers\ModelAttributesReplacer::makeWithModel($this->user),
92-
93-
function($html) {
94-
//
95-
}
96-
];
97-
}
98-
}
99-
```
33+
2. Email Templates & Placeholders
10034

10135
## Scheduler
10236

103-
To set up a mail to be sent after or before an event, you can do this by using `Scheduler` facade.
37+
To set up a mail to be sent after or before an event, you can do this by using the `Scheduler` facade.
10438

10539
Firstly lets set up a mail scheduler:
10640

@@ -354,6 +288,73 @@ Package provides the `Binarcode\LaravelMailator\Console\MailatorSchedulerCommand
354288
$schedule->command(MailatorSchedulerCommand::class)->everyThirtyMinutes();
355289
```
356290

291+
292+
## Templating
293+
294+
To create an email template:
295+
296+
``` php
297+
$template = Binarcode\LaravelMailator\Models\MailTemplate::create([
298+
'name' => 'Welcome Email.',
299+
'from_email' => 'from@bar.com',
300+
'from_name' => 'From Bar',
301+
'subject' => 'Welcome to Mailator.',
302+
'html' => '<h1>Welcome to the party!</h1>',
303+
]);
304+
```
305+
306+
Adding some placeholders with description to this template:
307+
308+
```php
309+
$template->placeholders()->create(
310+
[
311+
'name' => '::name::',
312+
'description' => 'Name',
313+
],
314+
);
315+
```
316+
317+
To use the template, you simply have to add the `WithMailTemplate` trait to your mailable.
318+
319+
This will enforce you to implement the `getReplacers` method, this should return an array of replacers to your template.
320+
The array may contain instances of `Binarcode\LaravelMailator\Replacers\Replacer` or even `Closure` instances.
321+
322+
Mailator shipes with a builtin replacer `ModelAttributesReplacer`, it will automaticaly replace attributes from the
323+
model you provide to placeholders.
324+
325+
The last step is how to say to your mailable what template to use. This could be done into the build method as shown
326+
bellow:
327+
328+
```php
329+
class WelcomeMailatorMailable extends Mailable
330+
{
331+
use Binarcode\LaravelMailator\Support\WithMailTemplate;
332+
333+
private Model $user;
334+
335+
public function __construct(Model $user)
336+
{
337+
$this->user = $user;
338+
}
339+
340+
public function build()
341+
{
342+
return $this->template(MailTemplate::firstWhere('name', 'Welcome Email.'));
343+
}
344+
345+
public function getReplacers(): array
346+
{
347+
return [
348+
Binarcode\LaravelMailator\Replacers\ModelAttributesReplacer::makeWithModel($this->user),
349+
350+
function($html) {
351+
//
352+
}
353+
];
354+
}
355+
}
356+
```
357+
357358
### Testing
358359

359360
``` bash
@@ -381,4 +382,3 @@ tracker.
381382
## License
382383

383384
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
384-

0 commit comments

Comments
 (0)