humans / laravel-semaphore
3.0.2
2020-02-08 16:03 UTC
Requires
- php: >=7.0
- illuminate/notifications: 5.5|5.6|5.7|5.8|^6.0
- illuminate/support: 5.5|5.6|5.7|5.8|^6.0
- kitetail/zttp: ^0.4.0
Requires (Dev)
- orchestra/testbench: ^3.5
This package is auto-updated.
Last update: 2020-02-09 03:45:17 UTC
README
Semaphore 是一家菲律宾短信服务提供商。
安装
composer require humans/laravel-semaphore
服务提供商
对于 Laravel 5.5 或更高版本,该包已通过 包发现 添加了服务提供商。
否则,在您的 config/app.php
文件中添加 Semaphore 服务提供商
return [ 'providers' => [ // ... Humans\Semaphore\ServiceProvider::class, ], ]
配置
在您的 .env
文件中,复制此默认模板,然后您可以添加您的 Semaphore API 密钥和发送者名称。
SEMAPHORE_KEY=
SEMAPHORE_FROM_NAME=
如果您想自定义配置文件,通过以下命令发布配置文件:
php artisan vendor:publish --tags=semaphore
使用
创建通知后,我们可以开始使用 Humans\Semaphore\SemaphoreChannel
来发送短信。
您应该在通知类中定义一个 toSemaphore
方法。此方法将接收一个 $notifiable
实体,并应返回一个 Humans\Semaphore\SemahporeMessage
实例。
use Humans\Semaphore\SemaphoreChannel; use Humans\Semaphore\SemaphoreMessage; class ReminderMessage extends notification { public function via($notifiable) { return ['slack', SemaphoreChannel::class]; } public function toSemaphore($notifiable) { return (new SemaphoreMessage) ->content("Hey {$notifiable->name}, don't forget to brush your teeth!"); } }
如果您想使用与您在 config/semaphore.php
文件中指定的名称不同的名称发送通知,您可以使用 SemaphoreMessage
实例上的 from
方法。
public function toSemaphore($notifiable) { return (new SemaphoreMessage) ->content("Hey {$notifiable->name}, don't forget to brush your teeth!") ->from('Humans'); }
在通过 SemaphoreChannel::class
发送通知时,通知系统 不会 自动在可通知条目上查找任何属性。要指定通知要发送到的哪个号码,在实体上定义一个 routeNotificationForSemaphore
方法。
<?php namespace App; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use Notifiable; /** * Route notifications for the Semaphore channel. * * @param \Illuminate\Notifications\Notification $notification * @return string */ public function routeNotificationForSemaphore($notification) { return $this->mobile; } }