gabeta / laravel-custom-sms-channels
Channels SMS notification for providers not supported by laravel by default.
Installs: 57
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 2
Forks: 2
Open Issues: 2
Language:Blade
Requires
- php: ^7.4|^8.0|^8.1
- cboden/ratchet: ^0.4.4
- guzzlehttp/guzzle: ^7.4
- illuminate/contracts: ^7.0|^8.0|^9.0
- illuminate/notifications: ^7.0|^8.0|^9.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.4|^3.8
- infobip/infobip-api-php-client: ^3.2
- nunomaduro/collision: ^5.10.0|^6.0
- nunomaduro/larastan: ^1.0|^2.0.1
- orchestra/testbench: ^5.0|^6.0|^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- twilio/sdk: ^6.38
Suggests
- infobip/infobip-api-php-client: Required to use infobip channels.
- twilio/sdk: Required to use twilio channels.
This package is auto-updated.
Last update: 2024-11-04 18:02:47 UTC
README
Laravel notification channels package for a few SMS providers. The specificity of this package is that you can combine several SMS sending services (supported by the package) in the same project without adding additional code. Have you always wanted to receive your SMS locally? preview them make consequent adjustments? We also offer you this functionality.
Installation
You can install the package via composer:
composer require gabeta/laravel-custom-sms-channels
You can publish the config file with:
php artisan vendor:publish --provider="Gabeta\CustomSmsChannels\CustomSmsChannelsServiceProvider" --tag="config"
Setting up your SMS provider
'default' => env('CUSTOM_SMS_CHANNEL', 'sms_log'), 'preview' => [ 'enable' => env('ENABLE_SMS_PREVIEW', true), 'domain' => null, 'path' => '/customs-sms-dashboard', ], 'providers' => [ 'sms_log' => [ 'config' => [ 'driver' => 'single', 'path' => storage_path('logs/custom-sms.log'), 'level' => 'info', ], ], 'infobip' => [ 'send_from' => env('INFOBIP_SEND_FROM'), 'api_host' => env('INFOBIP_API_HOST'), 'api_key_prefix' => env('INFOBIP_API_KEY_PREFIX'), 'api_key' => env('INFOBIP_API_KEY'), ] .... ]
Usage
Now you can use the channel in your via()
method inside the notification:
use Illuminate\Notifications\Notification; class WelcomeNotification extends Notification { public function via($notifiable) { return ['customsms']; } public function toCustomSms($notifiable) { return "Hello Laravel Community from Ivory Coast (Côte D'ivoire)"; } }
The customsms
channel will automatically use the provider you have defined
by default in your configuration file. It should be noted that a channel
will be created for each provider supported by the package.
See the list of channels supported.
In order to let your Notification know which user(s) phone number you are targeting,
add the routeNotificationForCustomSms
method to your Notifiable model.
The routeNotificationForCustomSms
method must return an instance of
Gabeta\CustomSmsChannels\PhoneNumber
.
use Gabeta\CustomSmsChannels\Facades\PhoneNumber; public function routeNotificationForCustomSms() { return PhoneNumber::setDialCode($this->dial_code) ->setPhone($this->phone); }
In the example above (the dial code and number are stored in separate fields)
we return an instance of Gabeta\CustomSmsChannels\PhoneNumber
while setting
the dial_code
without any prefix (+
or 00
) and the phone number.
There are providers that use the dial code and number without a prefix to send SMS
others use the +
or 00
prefix. The system will take care of the formatting according to
of each provider. If the number and dial code are stored in the same field you can
set with method.
use Gabeta\CustomSmsChannels\Facades\PhoneNumber; public function routeNotificationForCustomSms() { return PhoneNumber::setRouteNotification($this->full_phone_number); }
We advise you to provide the telephone number without the prefix. As mentioned above top the system will take care of the prefixing according to the provider.
Preview SMS Localy
To preview your SMS locally use the sms_log
driver activate the preview
in your config file.
Publish dashboard assets:
php artisan vendor:publish --provider="Gabeta\CustomSmsChannels\CustomSmsChannelsServiceProvider" --tag="public"
Go to: http://YOUR_HOST/customs-sms-dashboard for preview your SMS.
Provider supporter
You could use via or route notification method if you want behavior
channel-specific. The package tries to find the via method and the route notification method
specific to its provider if it does not find it it will call the routeNotificationForCustomSms
functions
and toCustomSms
.
Would you like to combine a notification channel package such as Laravel vonage package with our package ? Yes it is possible. you must first install their package then add their channel with null value in the supported provider in the config file.
Example:
'providers' => [ 'vonage' => null ]
Testing
composer test
Credits
License
The MIT License (MIT). Please see License File for more information.