This package makes it easy to sent Kavenegar Notifications with Laravel 5.3+.
You can install the package via composer:
composer require gdpa/kavenegar
Install for laravel 7:
composer require gdpa/kavenegar:^3.4
Install for laravel 6:
composer require gdpa/kavenegar:^2.0
Install for laravel < 5.8:
composer require gdpa/kavenegar:^1.0
Add your Kavenegar REST API Key to your config/services.php
:
// config/services.php
...
'kavenegar' => [
'api_key' => env('KAVENEGAR_API_KEY'),
],
...
There are two channels that you can use in your via()
method inside the notification:
KavenegarChannel
which represent simple send
api and KavenegarVerifyChannel
which provide verify lookup
api.
use NotificationChannels\Kavenegar\KavenegarChannel;
use NotificationChannels\Kavenegar\KavenegarMessage;
use Illuminate\Notifications\Notification;
class ProjectCreated extends Notification
{
public function via($notifiable)
{
return [KavenegarChannel::class];
}
public function toKavenegar($notifiable)
{
return KavenegarMessage::create()
->sender("your-desired-sender-number")
->message('Hello world');
}
}
use NotificationChannels\Kavenegar\KavenegarVerifyChannel;
use NotificationChannels\Kavenegar\KavenegarMessage;
use Illuminate\Notifications\Notification;
class ProjectCreated extends Notification
{
public function via($notifiable)
{
return [KavenegarVerifyChannel::class];
}
public function toKavenegar($notifiable)
{
return KavenegarMessage::create()
->template("your-template-key(Refer to Kavenegar Docs)")
->type('sms')
->token('your default token on your verify message template')
->token('additional token data. For example token10', 10);
}
}
In order to let your Notification know which Kavenegar user you are targeting, add the routeNotificationForKavenegar
method to your Notifiable model.
This method needs to return an array containing the mobile number of your receptor.
public function routeNotificationForKavenegar()
{
return [
'mobile_number' => 'receptor mobile number',
];
}
sender('')
: Accepts a string value for setting sender number on kavenegar.message()
: Accepts a string value for setting your sms message.template()
: Accepts a string value for setting your sms template.type()
: Accepts a string value for setting your service type (sms, voice, ...).tokens()
: Accepts two string value for setting your tokens. Second string is optional and in case you don't provide it, it set your default token.
Please see CHANGELOG for more information what has changed recently.
$ composer test
If you discover any security related issues, please email morteza.poussaneh@gmail.com instead of using the issue tracker.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.