moririnson / laravel-line-notify
为 Laravel 的 line 通知
1.1.0
2021-02-14 17:48 UTC
Requires
- php: >=7.0
- guzzlehttp/guzzle: >=6.0
- illuminate/notifications: >=6.0
Requires (Dev)
- mockery/mockery: *
- orchestra/testbench: >=4.0
- phpunit/phpunit: >=6.0
- squizlabs/php_codesniffer: 3.*
README
需求
- PHP 7.0+
- Laravel 5.5+
安装
composer require moririnson/laravel-line-notify
使用
通知
将 token 添加到你的可通知对象中。
/** * @return string token */ public function routeNotificationForLINE() { return 'ACCESS_TOKEN_HERE'; }
通过 make:notification
创建通知,并实现如下。
use Illuminate\Notifications\Notification; use Moririnson\LINENotify\Channels\LINENotifyChannel; use Moririnson\LINENotify\Messages\LINENotifyMessage; class LineNotify extends Notification { private $message; public function __construct($message) { $this->message = $message; } public function via($notifiable) { return [LINENotifyChannel::class] } public function toLINE($notifiable) { return (new LINENotifyMessage())->message($this->message); } }
然后你可以调用 notify()
。
$notifiable->notify(new LINENotify('test message'));
日志记录
将此配置添加到 logging.php
。
'stack' => [
'driver' => 'stack',
'channels' => ['line'],
],
'line' => [
'driver' => 'custom',
'token' => env('LOG_LINE_NOTIFY_ACCESS_TOKEN'),
'via' => \Moririnson\LINENotify\Logging\LINENotifyLogger::class,
'level' => 'error',
],
测试
composer test
许可证
MIT 许可证 (MIT),请参阅 许可证文件 获取更多信息。