websms/laravel-notification

此包最新版本(1.0.0)没有可用的许可证信息。

WebSms Laravel 通知

安装数: 11,687

依赖者: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 2

开放问题: 0

类型:laravel-package

1.0.0 2019-09-28 06:45 UTC

This package is auto-updated.

Last update: 2024-09-28 18:21:29 UTC


README

WebSms Laravel 通知

安装

您可以通过 composer 安装此包

$ composer require websms/laravel-notification

您必须安装服务提供者

// config/app.php
'providers' => [
    ...
    Websms\LaravelNotification\WebSmsServiceProvider::class,
]

设置您的 WebSms 账户

将您的 WebSms 用户名、密码和发送者号码添加到 config/services.php

// config/services.php

...
'websms' => [
'username' => env('WEBSMS_USERNAME'),
'password' => env('WEBSMS_PASSWORD'),
'sendNumber' => env('WEBSMS_SENDNUMBER'),
],
...
// .env

WEBSMS_USERNAME=your_username
WEBSMS_PASSWORD=your_password
WEBSMS_SENDNUMBER=send_number

使用方法

现在您可以在通知内的 via() 方法中使用该通道

/**
 * Get the notification's delivery channels.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function via($notifiable)
{
    return [WebSmsChannel::class];
}

/**
 * Get the sms representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return string
 */
public function toSms($notifiable)
{
    $webSmsMessage = new WebSmsMessage();
    $webSmsMessage->setFrom(env('WEBSMS_SENDNUMBER'));
    $webSmsMessage->setTo($notifiable->routeNotificationFor('sms'));
    $webSmsMessage->setMessage($this->message);

    return $webSmsMessage;
}

为了让您的通知知道您发送到的电话号码,请将 routeNotificationForSms 方法添加到您的 Notifiable 模型中,例如您的 User 模型

public function routeNotificationForSms()
{
    return $this->phone; // where `phone` is a field in your users table;
}

贡献者