Files

94 lines
2.9 KiB
PHP
Raw Permalink Normal View History

2026-03-15 17:08:23 +07:00
<?php
declare(strict_types=1);
namespace Modules\RestaurantDelivery\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Modules\RestaurantDelivery\Models\Delivery;
class DeliveryStatusNotification extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*/
public function __construct(
public readonly Delivery $delivery,
public readonly string $recipientType = 'customer'
) {
$this->onQueue(config('restaurant-delivery.queue.queues.notifications', 'restaurant-delivery-notifications'));
}
/**
* Get the notification's delivery channels.
*/
public function via(object $notifiable): array
{
return array_filter(config('restaurant-delivery.notifications.channels', ['database']));
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->subject("Delivery Update: {$this->delivery->status->label()}")
->greeting('Hello!')
->line("Your delivery #{$this->delivery->tracking_code} status has been updated.")
->line("New Status: {$this->delivery->status->label()}")
->line($this->delivery->status->description())
->action('Track Delivery', $this->getTrackingUrl())
->line('Thank you for using our delivery service!');
}
/**
* Get the array representation of the notification.
*/
public function toArray(object $notifiable): array
{
return [
'type' => 'delivery_status',
'delivery_id' => $this->delivery->id,
'tracking_code' => $this->delivery->tracking_code,
'status' => $this->delivery->status->value,
'status_label' => $this->delivery->status->label(),
'status_description' => $this->delivery->status->description(),
'rider' => $this->delivery->rider ? [
'name' => $this->delivery->rider->full_name,
'phone' => $this->delivery->rider->phone,
] : null,
];
}
/**
* Get FCM data for push notification.
*/
public function toFcm(): array
{
return [
'title' => 'Delivery Update',
'body' => $this->delivery->status->description(),
'data' => [
'type' => 'delivery_status',
'delivery_id' => (string) $this->delivery->id,
'tracking_code' => $this->delivery->tracking_code,
'status' => $this->delivery->status->value,
],
];
}
/**
* Get tracking URL.
*/
protected function getTrackingUrl(): string
{
return url("/track/{$this->delivery->tracking_code}");
}
}