work_order = $work_order; } /** * Get the notification's delivery channels. */ public function via(): array { if (! $this->work_order->notify) { return []; } return [WeComChannel::class, WebChannel::class]; } /** * Get the array representation of the notification. */ public function toArray(WorkOrderModel $workOrder): array { $array = $workOrder->toArray(); $array['latest_reply'] = $workOrder->replies()->latest()->first()?->toArray() ?? []; $array['event'] = 'work-order.'.$workOrder->status; return $array; } public function toWeCom(WorkOrderModel $workOrder): false|array { $workOrder->load(['module', 'user']); return [ 'key' => $workOrder->wecom_key, 'view' => 'notifications.work_order', 'data' => $workOrder, ]; } }