Skip to content

Commit f252588

Browse files
authored
Fix for "A message can only have one of the following targets" error (#116)
1 parent 11666ea commit f252588

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/FcmMessage.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,29 @@ public function setCondition(?string $condition): self
258258

259259
public function toArray()
260260
{
261-
return [
261+
$data = [
262262
'name' => $this->getName(),
263263
'data' => $this->getData(),
264264
'notification' => ! is_null($this->getNotification()) ? $this->getNotification()->toArray() : null,
265265
'android' => ! is_null($this->getAndroid()) ? $this->getAndroid()->toArray() : null,
266266
'webpush' => ! is_null($this->getWebpush()) ? $this->getWebpush()->toArray() : null,
267267
'apns' => ! is_null($this->getApns()) ? $this->getApns()->toArray() : null,
268268
'fcm_options' => ! is_null($this->getFcmOptions()) ? $this->getFcmOptions()->toArray() : null,
269-
'token' => $this->getToken(),
270-
'topic' => $this->getTopic(),
271-
'condition' => $this->getCondition(),
272269
];
270+
271+
if ($token = $this->getToken()) {
272+
$data['token'] = $token;
273+
}
274+
275+
if ($topic = $this->getTopic()) {
276+
$data['topic'] = $topic;
277+
}
278+
279+
if ($condition = $this->getCondition()) {
280+
$data['condition'] = $condition;
281+
}
282+
283+
return $data;
273284
}
274285

275286
/**

0 commit comments

Comments
 (0)