This package makes it easy to send Sms notifications using Infobip service with Laravel 5.5 and above.
You can install the package via composer:
composer require princeton255/laravel-notifications-infobip
Add your Infobip Account Username, Password, and From Number to your config/services.php
:
// config/services.php
...
'infobip' => [
'username' => env('INFOBIP_USERNAME'),
'password' => env('INFOBIP_PASSWORD'),
'from' => env('INFOBIP_FROM', 'IBTEST'),
],
...
To change Base URL
to personal use this (See more)
...
'infobip' => [
...
'baseUrl' => env('INFOBIP_BASE_URL', null),
],
...
Now you can use the channel in your via()
method inside the notification:
use NotificationChannels\Infobip\InfobipChannel;
use NotificationChannels\Infobip\InfobipMessage;
use Illuminate\Notifications\Notification;
class AccountApproved extends Notification
{
public function via($notifiable)
{
return [InfobipChannel::class];
}
public function toInfobip($notifiable)
{
return (new InfobipMessage())
->content("Your {$notifiable->service} account was approved!");
}
}
In order to let your Notification know which phone are you sending to, the channel will look for the phone_number
attribute of the Notifiable model. If you want to override this behaviour, add the routeNotificationForInfobip
method to your Notifiable model.
public function routeNotificationForInfobip()
{
return '+1234567890';
}
from('')
: Accepts a phone to use as the notification sender.content('')
: Accepts a string value for the notification body.
use App\Notifications\ExampleInfobipNotification;
use Illuminate\Support\Facades\Notification;
Notification::send($user, new ExampleInfobipNotification());
// where $user implements `Illuminate\Notifications\Notifiable` trait
use App\Notifications\ExampleInfobipNotification;
$user->notify(new ExampleInfobipNotification($invoice));
<?php
namespace App\Notifications;
use Illuminate\Notifications\Notification;
use NotificationChannels\Infobip\InfobipChannel;
use NotificationChannels\Infobip\InfobipMessage;
class ExampleInfobipNotification extends Notification
{
public function via($notifiable)
{
return [InfobipChannel::class];
}
public function toInfobip($notifiable)
{
return (new InfobipMessage())
// Customize your msg content here
->content("Your {$notifiable->service} account was approved!");
}
}
<?php
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use Notifiable;
}
For more details you can check out this link on Laravel documentation
$ ./vendor/bin/phpunit
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
- Based on Twilio SMS Notification channel for Laravel
- This project uses the Infobip Client library, and wraps it for smooth use in Laravel
The MIT License (MIT).