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
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
统计信息
- 总下载量: 62
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-11