101 lines
2.9 KiB
PHP
101 lines
2.9 KiB
PHP
|
|
<?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 RiderAssignedNotification extends Notification implements ShouldQueue
|
||
|
|
{
|
||
|
|
use Queueable;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create a new notification instance.
|
||
|
|
*/
|
||
|
|
public function __construct(
|
||
|
|
public readonly Delivery $delivery
|
||
|
|
) {
|
||
|
|
$this->onQueue(config('restaurant-delivery.queue.queues.notifications', 'restaurant-delivery-notifications'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the notification's delivery channels.
|
||
|
|
*/
|
||
|
|
public function via(object $notifiable): array
|
||
|
|
{
|
||
|
|
return ['database'];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the mail representation of the notification.
|
||
|
|
*/
|
||
|
|
public function toMail(object $notifiable): MailMessage
|
||
|
|
{
|
||
|
|
$rider = $this->delivery->rider;
|
||
|
|
|
||
|
|
return (new MailMessage)
|
||
|
|
->subject('Rider Assigned to Your Delivery')
|
||
|
|
->greeting('Good news!')
|
||
|
|
->line("A rider has been assigned to your delivery #{$this->delivery->tracking_code}.")
|
||
|
|
->line("Rider: {$rider->full_name}")
|
||
|
|
->line("Vehicle: {$rider->vehicle_type}")
|
||
|
|
->action('Track Your Delivery', $this->getTrackingUrl())
|
||
|
|
->line('You can now track your rider in real-time!');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the array representation of the notification.
|
||
|
|
*/
|
||
|
|
public function toArray(object $notifiable): array
|
||
|
|
{
|
||
|
|
$rider = $this->delivery->rider;
|
||
|
|
|
||
|
|
return [
|
||
|
|
'type' => 'rider_assigned',
|
||
|
|
'delivery_id' => $this->delivery->id,
|
||
|
|
'tracking_code' => $this->delivery->tracking_code,
|
||
|
|
'rider' => [
|
||
|
|
'id' => $rider->id,
|
||
|
|
'name' => $rider->full_name,
|
||
|
|
'phone' => $rider->phone,
|
||
|
|
'photo' => $rider->photo_url,
|
||
|
|
'rating' => $rider->rating,
|
||
|
|
'vehicle_type' => $rider->vehicle_type,
|
||
|
|
],
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get FCM data for push notification.
|
||
|
|
*/
|
||
|
|
public function toFcm(): array
|
||
|
|
{
|
||
|
|
$rider = $this->delivery->rider;
|
||
|
|
|
||
|
|
return [
|
||
|
|
'title' => 'Rider Assigned',
|
||
|
|
'body' => "{$rider->full_name} is picking up your order",
|
||
|
|
'data' => [
|
||
|
|
'type' => 'rider_assigned',
|
||
|
|
'delivery_id' => (string) $this->delivery->id,
|
||
|
|
'tracking_code' => $this->delivery->tracking_code,
|
||
|
|
'rider_id' => (string) $rider->id,
|
||
|
|
'rider_name' => $rider->full_name,
|
||
|
|
],
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get tracking URL.
|
||
|
|
*/
|
||
|
|
protected function getTrackingUrl(): string
|
||
|
|
{
|
||
|
|
return url("/track/{$this->delivery->tracking_code}");
|
||
|
|
}
|
||
|
|
}
|