定制 think.studio/laravel-notification-tracker 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

think.studio/laravel-notification-tracker

最新稳定版本:1.4.0

Composer 安装命令:

composer require think.studio/laravel-notification-tracker

包简介

Track status of notifications sent by application.

README 文档

README

Packagist License Packagist Version Total Downloads Build Status Code Coverage Scrutinizer Code Quality

Track status of notifications sent by application.

Installation

Install the package via composer:

composer require think.studio/laravel-notification-tracker

You can publish the config file with:

php artisan vendor:publish --provider="NotificationTracker\ServiceProvider" --tag="config"

Configuration

public function register()
{
    // cancel default migrations files
    \NotificationTracker\NotificationTracker::ignoreMigrations();
    // cancel default web routes implementation
    \NotificationTracker\NotificationTracker::ignoreRoutes();
    // change class names what stored in database
    \NotificationTracker\NotificationTracker::classMap([
        'registration_confirmation' => \App\Notifications\RegistrationNotification::class,
    ]);
}

Usage

For your notification please implement Interface Trackable, use trait HasTracker.

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use NotificationTracker\Notification\HasTracker;
use NotificationTracker\Notification\Trackable;

class CertifiedNotification extends Notification implements ShouldQueue, Trackable
{
    use Queueable, HasTracker;
    
    public Document $document;
    
    public function __construct(Document $document)
    {
        $this->document = $document;
    }

    public function via($notifiable = null)
    {
        return ['mail', 'custom'];
    }

    public function toMail($notifiable)
    {
        $message = (new MailMessage)->subject('Certificate created');

        $message->line('Thank you!');

        // Initialise tracker
        return $this->tracker()
            // You can add metadata to channel row. Using callback, or passing key->value
            ->trackerMeta(fn(\JsonFieldCast\Json\AbstractMeta $meta, $trackedChannel) => $meta->toMorph('document', $this->document))
            ->trackerMeta('document_category', $this->document->category?->name)
            // Save tracked data
            ->trackMailMessage($message, $notifiable);
    }

    public function toCustom($notifiable)
    {
        /** @var \NotificationTracker\Models\TrackedChannel $trackedChannel */
        $trackedChannel = $this->tracker()->track('custom', $notifiable);

        return [
            'subject' => 'Foo',
            'body' => "Foo {$trackedChannel->getClickTrackerUrl('https://test.com')} {$trackedChannel->getPixelImageHtml()}",
        ];
    }
}

Credits

  • Think Studio

统计信息

  • 总下载量: 62
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-11