avinashmphp/textlocal

Laravel 的 Textlocal SMS 通道

v1.1 2019-04-04 07:14 UTC

This package is auto-updated.

Last update: 2024-09-04 19:45:38 UTC


README

使用 Textlocal 官方 PHP 类,此包使得在 Laravel 中发送 SMS 通知变得简单。

要求

  • 免费注册 Textlocal 账户
  • 在设置部分创建一个新的 API 密钥

安装

您可以通过 composer 安装此包

composer require avinashmphp/textlocal

步骤:1

将 ServiceProvider 添加到 config/app.php 文件中的 providers 数组

Avinashmphp\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 Avinashmphp\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

为了让您的通知知道您发送给哪个手机,通道将在可通知模型(Notifiable)中寻找 phone_number 属性。如果您想覆盖此行为,请将 routeNotificationForTextlocal 方法添加到您的 Notifiable 模型。

public function routeNotificationForTextlocal()
{
    return $this->mobile; // where 'mobile' is a field in users table;
}

许可证

MIT 许可证。