This package makes it easy to send sms notifications using Twilio with Laravel 8.x, 9.x, 10.x
You can install this package via composer:
composer require macellan/twilio
Add your Twilio configs to your config/services.php:
// config/services.php
...
'sms' => [
'twilio' => [
'account_sid' => env('TWILIO_ACCOUNT_SID', ''),
'auth_token' => env('TWILIO_AUTH_TOKEN', ''),
'from' => env('TWILIO_FROM', ''),
'enable' => env('TWILIO_ENABLE', false),
'debug' => env('TWILIO_DEBUG', false), // Will log sending attempts and results
'sandbox_mode' => env('TWILIO_SANDBOX_MODE', false), // Will not invoke API call
],
],
...
You can use the channel in your via() method inside the notification:
use Illuminate\Notifications\Notification;
use Macellan\Twilio\TwilioSmsMessage;
class TestNotification extends Notification
{
public function via($notifiable)
{
return ['twilio'];
}
public function toTwilio(object $notifiable): TwilioSmsMessage
{
return new TwilioSmsMessage('Twilio test message');
}
}
In your notifiable model, make sure to include a routeNotificationForSms() method, which returns a phone number.
public function routeNotificationForSms()
{
return $this->phone;
}
Sometimes you may need to send a notification to someone who is not stored as a "user" of your application. Using the Notification::route method, you may specify ad-hoc notification routing information before sending the notification:
Notification::route('sms', '+905554443322')
->notify(new TestNotification());
composer test
Please see CHANGELOG for more information what has changed recently.