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) && $delivery->deliveryAppointment->cubic_meter>0 ? ($count>1 ? $delivery->deliveryAppointment->cubic_meter."/".$count : $delivery->deliveryAppointment->cubic_meter) : ""; $delivery->tonne = isset($delivery->deliveryAppointment->tonne) && $delivery->deliveryAppointment->tonne>0 ? ($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"; } }