Files

56 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2026-03-15 17:08:23 +07:00
<?php
declare(strict_types=1);
namespace Modules\RestaurantDelivery\Events;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Modules\RestaurantDelivery\Models\Delivery;
class DeliveryCreated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public function __construct(
public readonly Delivery $delivery
) {}
/**
* Get the channels the event should broadcast on.
*/
public function broadcastOn(): array
{
return [
new PrivateChannel("restaurant.{$this->delivery->restaurant_id}.deliveries"),
];
}
/**
* Get the data to broadcast.
*/
public function broadcastWith(): array
{
return [
'delivery_id' => $this->delivery->id,
'tracking_code' => $this->delivery->tracking_code,
'restaurant_id' => $this->delivery->restaurant_id,
'status' => $this->delivery->status,
'pickup_address' => $this->delivery->pickup_address,
'drop_address' => $this->delivery->drop_address,
'created_at' => $this->delivery->created_at->toIso8601String(),
];
}
/**
* The event's broadcast name.
*/
public function broadcastAs(): string
{
return 'delivery.created';
}
}