multicaret / unifonic-notification-channel
Unifonic 通知通道适用于 laravel。
v3.0.0
2021-06-01 18:38 UTC
Requires
- php: ^7.4|^8.0
- multicaret/laravel-unifonic: ^2.0
Requires (Dev)
- illuminate/notifications: ~v8.35.1
- mockery/mockery: ^1.0
- phpunit/phpunit: ^9.5.0
README
适用于 Laravel 8.x 及更高版本的 Unifonic 通知通道
Unifonic 通道使您能够将 Laravel 通知以短信的形式发送出去
安装
您可以通过 composer 安装此包
composer require multicaret/unifonic-notification-channel
服务提供者会自动加载。
设置 Unifonic 服务
查看 Laravel Unifonic 库 的配置
使用方法
要使用此包,您需要在 Laravel 应用程序中创建一个通知类,例如下面的 InvoicePaid
,确保查看 Laravel 的文档 了解此过程。
通知示例
<?php namespace App\Notifications; use Illuminate\Notifications\Notification; use Multicaret\Notifications\Messages\UnifonicMessage; class InvoicePaid extends Notification { private $message; /** * Create a new notification instance. * * @param $message */ public function __construct($message) { $this->message = $message; } /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return [ 'unifonic', ]; } /** * Get the text message representation of the notification * * @param mixed $notifiable * * @return UnifonicMessage */ public function toUnifonic($notifiable) { return (new UnifonicMessage()) ->content($this->message); } }
或将您想要的内容直接传递给构造函数
public function toUnifonic($notifiable) { return new UnifonicMessage('Laravel notifications are awesome!'); }
发送通知
在 Laravel 中发送通知有两种方法
方法 1
在具有 Notifiable
特性的任何模型上使用 notify()
函数。为了实现这一点,您需要提供适当的列作为接收者号码,如下面的示例所示,此函数位于 User 模型中(您可能需要在不同的模型中编写它,只需确保使用 use Notifiable
即可)
/** * Route notifications for the Unifonic channel. * * @param \Illuminate\Notifications\Notification $notification * * @return string */ public function routeNotificationForUnifonic($notification) { return $this->phone; // where phone is the column within your, let's say, users table. }
方法 2
在通知类上使用 route()
静态函数。
Notification::route('unifonic', 'xxxxx') ->notify( new \App\Notifications\InvoicePaid('Laravel notifications are awesome!') ); // where xxxxx is the phone number you want to sent to, // i.e: 1xxxxxxx - NO NEED for _00_ or _+_
贡献
查看 CONTRIBUTING 指南。
变更日志
请参阅 CHANGELOG 了解最近更改的更多信息。