This package makes it easy to send notifications using MoceanAPI with Laravel 5.5+ and 6.0
To install the library, run this command in terminal:
composer require laravel-notification-channels/moceanapi
You must publish the config file as this will use Laravel Mocean as a package.
php artisan vendor:publish --provider="Mocean\Laravel\MoceanServiceProvider"
Setup ur configurations
// config/mocean.php
...
'MOCEAN_API_KEY' => 'YOUR MOCEAN_API_KEY',
'MOCEAN_API_SECRET' => 'YOUR MOCEAN_API_SECRET',
...
Create a notification class, refer laravel official docs
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use NotificationChannels\MoceanApi\MoceanApiChannel;
use NotificationChannels\MoceanApi\MoceanApiSmsMessage;
class InvoicePaid extends Notification
{
use Queueable;
public function via($notifiable)
{
return [MoceanApiChannel::class];
}
public function toMoceanapi($notifiable)
{
//return the text message u want to send here
return 'You have received an invoice';
//you can also return an array for custom options, refer moceanapi docs
return [
'mocean-text' => 'You have received an invoice',
'mocean-dlr-url' => 'https://test.com'
];
//you can also return a MoceanApiSmsMessage instance
return (new MoceanApiSmsMessage())
->setText('You have received an invoice');
}
}
to specify which attribute should be used to be a notifiable entity, create method routeNotificationForMoceanapi
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
public function routeNotificationForMoceanapi($notification)
{
//make sure user model has this attribute, else the notification will not be sent
return $this->phone;
}
}
send the notification to a user
$user->notify(new InvoicePaid());
you can also send the notification to a custom phone number without using user model
use Notification;
Notification:route('moceanapi', '60123456789')
->notify(new InvoicePaid());
setFrom('')
: Set the SMS Sender IDsetTo('')
: Set the phone number of the receiversetText('')
: Set the contents of the message
for more info, please visit MoceanAPI docs
Please see CHANGELOG for more information what has changed recently.
$ composer test
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.