niisan / laravel-sms-notification
Add SMS notification channel to laravel.
Installs: 31 605
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- illuminate/notifications: ^5.8 || ^6.0 || ^7.0 || ^8.0
Requires (Dev)
- mockery/mockery: ^1.4
- phpunit/phpunit: ^9.5
- twilio/sdk: ^6.15
README
Add SMS notification channnel to laravel.
Install
Fisrt, install package via composer.
composer require niisan/laravel-sms-notification
And install using client sdk. If we use twilio, we install twilio sdk.
composer require twilio/sdk
Then we publish configuration.
php artisan vendor:publish --provider "Niisan\Notification\SmsNotificationServiceProvider"
Usage
Set .env
.
SMS_DRIVER=twilio
SMS_DEFAULT_FROM='+1111222233'
TWILIO_SID=***********************
TWILIO_TOKEN=***********************
In notification class, we can write followin:
public function via($notifiable) { return ['sms']; } public function toSms($notifiable) { return (new SmsMessage) ->body('hello world! ' . $notifiable->name); }
And in notifiable model, we get phone_number
from routeNotificationForSms
method to send messages:
public function routeNotificationForSms() { return $this->phone_number; }
In this case, SMS sent from the env value: SMS_DEFAULT_FROM
.
Otherwise, set to
and from
by SmsMessage class:
public function toSms($notifiable) { return (new SmsMessage) ->body('hello world! ' . $notifiable->name) ->to('+2222333344') ->from('+1111222233'); }
Unicode
if we want to use unicode string, we use unicode method:
public function toSms($notifiable) { return (new SmsMessage) ->body('hello world! ' . $notifiable->name) ->unicode(); }