alhaji-aki / laravel-textcus
Laravel wrapper for textcus sms api
1.0.4
2021-03-10 18:07 UTC
Requires
- php: >=7.1
- guzzlehttp/guzzle: ^7.0.1
- illuminate/notifications: ~6.0 || ~7.0 || ~8.0
- illuminate/support: ~6.0 || ~7.0 || ~8.0
Requires (Dev)
- mockery/mockery: ^1.3
- orchestra/testbench: ^5.0|^6.0
- phpunit/phpunit: ^9.1
README
This package makes it easy to send notifications using textcus with Laravel 6.x, 7.x & 8.x.
Contents
Installation
You can install the package via composer:
composer require alhaji-aki/laravel-textcus
Setting up the textcus service
Add your Textcus sender id and api key to your config/services.php
:
// config/services.php ... 'textcus' => [ 'api_key' => env('TEXTCUS_API_KEY'), 'sender_id' => env('TEXTCUS_SENDER_ID'), ], ...
Usage
To route Textcus notifications to the proper phone number, define a routeNotificationForTextcus
method on your notifiable entity:
class User extends Authenticatable { use Notifiable; /** * Route notifications for the Textcus channel. * * @param \Illuminate\Notifications\Notification $notification * @return string */ public function routeNotificationForTextcus() { // NOTE: this is because you have to remove the + sign infront of the number in international formt return substr($this->mobile, 1); } }
You can use the channel in your via()
method inside the notification:
use Illuminate\Notifications\Notification; use AlhajiAki\Textcus\Messages\TextcusMessage; class AccountApproved extends Notification { public function via($notifiable) { return ['textcus']; } public function toTextcus($notifiable) { return (new TextcusMessage()) ->content("Your {$notifiable->service} account was approved!"); } }
Testing
vendor/bin/phpunit
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see License File for more information.