macellan/twilio
Composer 安装命令:
composer require macellan/twilio
包简介
Twilio SMS notification channel for Laravel
README 文档
README
This package makes it easy to send sms notifications using Twilio with Laravel 12.x
Contents
Installation
You can install this package via composer:
composer require macellan/twilio
Setting up the Twilio service
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 ], ], ...
Usage
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): array { 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(): string { return $this->phone; }
On-Demand Notifications
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());
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Credits
统计信息
- 总下载量: 3.78k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-29