meshgroup / megafon-notification-channel
Requires
- php: >=5.6.4
- ext-mbstring: *
- guzzlehttp/guzzle: ^7.4.5
- illuminate/notifications: 5.1 - 8.9
- illuminate/queue: 5.1 - 8.9
- illuminate/support: 5.1 - 8.9
README
This package makes it easy to send notifications using megafon with Laravel 5.3+.
Contents
Installation
You can install the package via composer:
composer require meshgroup/megafon-notification-channel
Then you must install the service provider:
// config/app.php 'providers' => [ ... Meshgroup\Megafon\MegafonServiceProvider::class, ],
Setting up the Megafon service
Add your Megafon login, password and default sender name (or phone number) to your config/services.php
:
// config/services.php ... 'megafon' => [ 'login' => env('MEGAFON_LOGIN'), 'password' => env('MEGAFON_PASSWORD'), 'sender' => 'John_Doe' ], ...
If you want use other host than
https://a2p-api.megalabs.ru/
, you MUST set custom host WITH trailing slash.
// .env
...
MEGAFON_HOST=https://a2p-api.megalabs.ru/
...
// config/services.php ... 'megafon' => [ ... 'host' => env('MEGAFON_HOST'), ... ], ...
Usage
You can use the channel in your via()
method inside the notification:
use Illuminate\Notifications\Notification; use Meshgroup\Megafon\MegafonMessage; use Meshgroup\Megafon\MegafonChannel; class AccountApproved extends Notification { public function via($notifiable) { return [MegafonChannel::class]; } public function toMegafon($notifiable) { return MegafonMessage::create("Task #{$notifiable->id} is complete!"); } }
In your notifiable model, make sure to include a routeNotificationForMegafon()
method, which returns a phone number
or an array of phone numbers.
public function routeNotificationForMegafon() { return $this->phone; }
Available methods
from()
: Sets the sender's name or phone number.
content()
: Set a content of the notification message.
sendAt()
: Set a time for scheduling the notification message.
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test