cuneytyuksel/toplusms

Laravel 通知扩展 for toplusmsapi.com

v1.0.6 2019-09-19 06:32 UTC

This package is auto-updated.

Last update: 2024-09-19 18:12:01 UTC


README

介绍

这是一个简单的Laravel通知通道。

安装

首先,您需要使用Composer要求该软件包。

composer require cuneytyuksel/toplusms

之后,从命令行运行 composer update

然后,通过添加服务提供者条目来更新 config/app.php

'providers' => [
	// ...
    Sms\TopluSms\TopluSmsProvider::class,
];

然后,通过添加您的toplusms凭据来更新 config/services.php

return [
   // ...
	,
        'toplusms' => [
            'username' => env('TOPLUSMS_USERNAME'),
            'password' => env('TOPLUSMS_PASSWORD'),
            'from' => env('TOPLUSMS_FROM', null), // Can be ovverdiden with $message->from() 
        ]
    // ...
];

用法

路由短信通知

为了发送短信消息,您需要为每个通知实体指定接收者。例如,在 app/user.php

    // ...
    public function routeNotificationForSms(){
        return $this->phone;
    }
    // ...

发送通知

通过方法

在您的通知类中,您可以定义通道为

    // ...
    public function via($notifiable)
    {
        return ['sms'];
    }
    // ...

toSMS 方法

您还需要定义,toSms 方法。您可以

  1. 发送一个简单的字符串作为
    // ...
    public function toSms($notifiable)
    {
        return "Hello World!";
    }
    // ...
  1. 或定义一个来自(发送者)以覆盖配置
    // ...
    public function toSms($notifiable)
    {
       $message = new SmsMessage("Hello World");
       $message->from("5xxxxxxxxx");
       return $message;
    }
    // ...