| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace App\Events;
- use App\DeliveryAppointmentCar;
- use Illuminate\Broadcasting\Channel;
- use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Foundation\Events\Dispatchable;
- use Illuminate\Queue\SerializesModels;
- class DeliveryAppointmentEvent implements ShouldBroadcast
- {
- use Dispatchable, SerializesModels;
- public $delivery;
- /**
- * Create a new event instance.
- *
- * @param DeliveryAppointmentCar|\stdClass $delivery
- *
- * @return void
- */
- public function __construct(DeliveryAppointmentCar $delivery)
- {
- $delivery->load(["deliveryAppointment"=>function($query){
- /** @var Builder $query */
- $query->withCount("cars");
- }]);
- $count = $delivery->deliveryAppointment->cars_count ?? 0;
- $delivery->warehouse = $delivery->deliveryAppointment->warehouse_id ?? "";
- $delivery->cubic_meter = isset($delivery->deliveryAppointment->cubic_meter) ? ($count>1 ? $delivery->deliveryAppointment->cubic_meter."/".$count : $delivery->deliveryAppointment->cubic_meter) : "";
- $delivery->tonne = isset($delivery->deliveryAppointment->tonne) ? ($count>1 ? $delivery->deliveryAppointment->tonne."/".$count : $delivery->deliveryAppointment->tonne) : "";
- $this->delivery = $delivery->withoutRelations();
- }
- /**
- * Get the channels the event should broadcast on.
- *
- * @return \Illuminate\Broadcasting\Channel|array
- */
- public function broadcastOn()
- {
- return new Channel('delivery');
- }
- public function broadcastAs()
- {
- return "car";
- }
- }
|