diff --git a/src/FcmMessage.php b/src/FcmMessage.php index bb68ff0..a1422ef 100644 --- a/src/FcmMessage.php +++ b/src/FcmMessage.php @@ -258,7 +258,7 @@ public function setCondition(?string $condition): self public function toArray() { - return [ + $data = [ 'name' => $this->getName(), 'data' => $this->getData(), 'notification' => ! is_null($this->getNotification()) ? $this->getNotification()->toArray() : null, @@ -266,10 +266,21 @@ public function toArray() 'webpush' => ! is_null($this->getWebpush()) ? $this->getWebpush()->toArray() : null, 'apns' => ! is_null($this->getApns()) ? $this->getApns()->toArray() : null, 'fcm_options' => ! is_null($this->getFcmOptions()) ? $this->getFcmOptions()->toArray() : null, - 'token' => $this->getToken(), - 'topic' => $this->getTopic(), - 'condition' => $this->getCondition(), ]; + + if ($token = $this->getToken()) { + $data['token'] = $token; + } + + if ($topic = $this->getTopic()) { + $data['topic'] = $topic; + } + + if ($condition = $this->getCondition()) { + $data['condition'] = $condition; + } + + return $data; } /**