abuhawwa / textlocal
Textlocal SMS通道用于Laravel
dev-master
2020-05-31 12:49 UTC
Requires
- php: ^5.6|^7.1
- illuminate/notifications: ^5.8 || ^6.0 || ^7.0
- illuminate/support: ^5.8 || ^6.0 || ^7.0
Requires (Dev)
- mockery/mockery: ^1.3
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-09-29 05:42:40 UTC
README
使用Textlocal官方PHP类,此包使您在Laravel中发送短信通知变得容易
需求
- 免费注册Textlocal账户
- 在设置部分创建一个新的API密钥
安装
您可以通过composer安装此包
composer require abuhawwa/textlocal
步骤:1
将ServiceProvider添加到config/app.php中的providers数组
Abuhawwa\Textlocal\TextlocalServiceProvider::class,
步骤:2
将分发配置文件复制到您的应用配置目录中 config/textlocal.php
php artisan vendor:publish --tag=textlocal
步骤:3
然后使用您的凭据更新config/textlocal.php。或者,您可以使用以下内容更新.env文件
TEXTLOCAL_KEY="" TEXTLOCAL_SENDER=""
步骤:4
现在您可以在通知中的via()方法中使用该通道
use Abuhawwa\Textlocal\TextlocalChannel; use Illuminate\Notifications\Notification; class PostApproved extends Notification { public function via($notifiable) { return [TextlocalChannel::class]; } public function toTextlocal($notifiable) { return "Your {$notifiable->service} account was approved!" } }
步骤:5
为了让您的通知知道您发送给哪个电话,该通道将在可通知模型的phone_number属性中查找。如果您想覆盖此行为,请将routeNotificationForTextlocal方法添加到您的可通知模型中。
public function routeNotificationForTextlocal() { return $this->mobile; // where 'mobile' is a field in users table; }