Skip to content

Commit fc135e3

Browse files
committed
docs: installation and usage
1 parent e123a1f commit fc135e3

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

README.md

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,89 @@ If you're just looking for a mailjet mail transport, check out [mailjet/laravel-
1414

1515
composer require yieldstudio/laravel-mailjet-notifier
1616

17+
## Configure
18+
19+
Just define these environment variables:
20+
21+
```dotenv
22+
MAILJET_APIKEY=
23+
MAILJET_APISECRET=
24+
MAILJET_SMSTOKEN=
25+
MAIL_FROM_ADDRESS=
26+
MAIL_FROM_NAME=
27+
MAILJET_SMS_SENDER=
28+
```
29+
30+
Make sure that MAIL_FROM_ADDRESS is an authenticated email on Mailjet, otherwise your emails will not be sent by the Mailjet API.
31+
32+
MAILJET_SMS_SENDER should be between 3 and 11 characters in length, only alphanumeric characters are allowed.
33+
34+
You can publish the configuration file with:
35+
36+
```shell
37+
php artisan vendor:publish --provider="YieldStudio\LaravelMailjetNotifier\MailjetNotifierServiceProvider" --tag="config"
38+
```
39+
1740
## Usage
1841

19-
TODO
42+
### Send email
43+
44+
```php
45+
<?php
46+
47+
namespace App\Notifications;
48+
49+
use Illuminate\Notifications\Notification;
50+
use YieldStudio\LaravelMailjetNotifier\MailjetEmailChannel;
51+
52+
class OrderConfirmation extends Notification
53+
{
54+
public function channels(): array
55+
{
56+
return [MailjetEmailChannel::class];
57+
}
58+
59+
public function toMailjetEmail($notifiable): MailjetEmailMessage
60+
{
61+
return (new MailjetEmailMessage())
62+
->templateId(999999) // Replace with your template ID
63+
->to($notifiable->firstname, $notifiable->email)
64+
->variable('firstname', $notifiable->firstname)
65+
->variable('order_ref', 'N°0000001');
66+
}
67+
}
68+
```
69+
70+
### Send sms
71+
72+
```php
73+
<?php
74+
75+
namespace App\Notifications;
76+
77+
use Illuminate\Notifications\Notification
78+
;use YieldStudio\LaravelMailjetNotifier\MailjetSmsChannel;
79+
use YieldStudio\LaravelMailjetNotifier\MailjetSmsMessage;
80+
81+
class ResetPassword extends Notification
82+
{
83+
public function __construct(protected string $code)
84+
{
85+
}
86+
87+
public function via()
88+
{
89+
return [MailjetSmsChannel::class];
90+
}
91+
92+
public function toMailjetSms($notifiable): MailjetSmsMessage
93+
{
94+
return (new MailjetSmsMessage())
95+
->to($notifiable->phone)
96+
->text(__('This is your reset code :code', ['code' => $this->code]));
97+
}
98+
}
99+
```
20100

21101
## Unit tests
22102

src/MailjetNotifierServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function boot(): void
1313
if ($this->app->runningInConsole()) {
1414
$this->publishes([
1515
__DIR__.'/../config' => config_path(),
16-
], 'mailjet-notifier-config');
16+
], 'config');
1717
}
1818
}
1919

0 commit comments

Comments
 (0)