<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
think.studio / laravel-notification-tracker example snippets
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,
]);
}
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()}",
];
}
}