norbis/laravel-log-notification-channel

1.0.0 2021-04-11 10:37 UTC

This package is auto-updated.

Last update: 2024-09-11 18:29:41 UTC


README

为 Laravel 7+ 发送通知到日志的组件。

内容

安装

使用 Composer 安装库

composer require norbis/laravel-log-notification-channel

服务提供者将自动加载,或者您可以手动添加

// config/app.php
'providers' => [
    ...
    NotificationChannels\LogChannel\LogChannelServiceProvider::class,
],

配置服务

在您的 config/services.php 中添加默认日志通知通道

// config/services.php
...
/* Настройки */
'logchannel' => [
    /* Канал лога уведомлений по-умолчанию */
    'channel' => 'daily',
],
...

使用

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

use Illuminate\Notifications\Notification;
use NotificationChannels\LogChannel\LogMessage;

class AccountApproved extends Notification
{
    public function via($notifiable)
    {
        return ['log'];
    }

    public function toLog($notifiable)
    {
        return LogMessage::create("Task #{$notifiable->id} is complete!");
    }
}

在您的通知接收者模型中添加 routeNotificationForLog() 方法,该方法将返回联系信息或联系人数组。

public function routeNotificationForLog()
{
    return $this->phone;
}

消息模型可用的方法

channel(): 设置消息日志通道。

content(): 设置消息内容。

extra(): 设置消息的额外数据。

变更

查看 变更 获取详细信息。

测试

$ composer test