Skip to content

Commit

Permalink
Fix for "A message can only have one of the following targets" error (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mgsmus authored Aug 22, 2022
1 parent 11666ea commit f252588
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/FcmMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,29 @@ 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,
'android' => ! is_null($this->getAndroid()) ? $this->getAndroid()->toArray() : null,
'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;
}

/**
Expand Down

0 comments on commit f252588

Please sign in to comment.