@@ -28,79 +28,13 @@ Publish config: `a vendor:publish --tag=mailator-config`
28
28
29
29
It has mainly 2 directions of usage:
30
30
31
- 1 . Email Templates & Placeholders
31
+ 1 . Schedule emails sending (or actions triggering)
32
32
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
100
34
101
35
## Scheduler
102
36
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.
104
38
105
39
Firstly lets set up a mail scheduler:
106
40
@@ -354,6 +288,73 @@ Package provides the `Binarcode\LaravelMailator\Console\MailatorSchedulerCommand
354
288
$schedule->command(MailatorSchedulerCommand::class)->everyThirtyMinutes();
355
289
```
356
290
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
+
357
358
### Testing
358
359
359
360
``` bash
@@ -381,4 +382,3 @@ tracker.
381
382
## License
382
383
383
384
The MIT License (MIT). Please see [ License File] ( LICENSE.md ) for more information.
384
-
0 commit comments