PHP code example of eugenefvdm / notification-subscriptions
1. Go to this page and download the library: Download eugenefvdm/notification-subscriptions library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
eugenefvdm / notification-subscriptions example snippets
use Eugenefvdm\NotificationSubscriptions\Traits\HasNotificationSubscriptions;
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable;
use HasNotificationSubscriptions;
use Eugenefvdm\NotificationSubscriptions\Notifications\BaseNotification;
class DailyReminder extends BaseNotification
{
use Queueable;
use Eugenefvdm\NotificationSubscriptions\Enums\RepeatFrequency;
use Eugenefvdm\NotificationSubscriptions\Notifications\BaseNotification;
class DailyReminder extends BaseNotification
{
use Queueable;
public static ?string $repeatFrequency = RepeatFrequency::Daily;
public static ?int $repeatInterval = 4; // optional
public static ?int $maxRepeats = 3; // optional defaults to 1
use Eugenefvdm\NotificationSubscriptions\Notifications\BaseNotification;
class DailyReminder extends BaseNotification
{
use Queueable;
public static ?Carbon $initialDelay = null;
/**
* Create a new notification instance.
*/
public function __construct()
{
self::$initialDelay = Carbon::now()->addWeek();
}
use Eugenefvdm\NotificationSubscriptions\Notifications\BaseNotification;
class DailyReminder extends BaseNotification
{
use Queueable;
public static ?string $category = 'reminders';
use Eugenefvdm\NotificationSubscriptions\Notifications\BaseNotification;
use Illuminate\Database\Eloquent\Model;
use App\Models\Product;
class ProductPriceNotification extends BaseNotification
{
use Queueable;
public ?Model $customModel; // Override $customModel
public function __construct(Product $product) // Type-hint Product in constructor
{
$this->customModel = $product;
}
public function toMail(object $notifiable): MailMessage
{
/** @var Product $product */
$product = $this->customModel;
return (new MailMessage)
->subject("Price Update for {$product->name}")
->markdown('notification.product-price-update', [
'product' => $product,
'subscription' => $this->getSubscriptionFromNotifiable($notifiable)
]);
}
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->markdown('notification.reminders.max-count', [
'subscription' => $this->getSubscriptionFromNotifiable($notifiable)
]);
}