Closed mgsmus closed 2 years ago
please merge this PR.
@HAstaShakiba Meanwhile you can use https://github.com/symplify/vendor-patches to patch the error
@atymic please merge this PR
@atymic kindly merge this PR
temporary resolution of the problem...
add "kreait/firebase-php": "6.3.1"
to composer.json
up
up
@atymic Why is this PR taking so long time to merge?
up
For real..? PR with such tiny changes takes forever to merge?
@atymic, could you take a look here? Thanks
up @atymic
👍
any solutions found for this ?
any solutions found for this ?
https://github.com/laravel-notification-channels/fcm/pull/116#issuecomment-1156475473
any solutions found for this ?
"kreait/firebase-php": "6.3.1" => add composer file but not working create the same issue
If the maintainer doesn't merge the PR, you could use your FcmMessage class to extend the original ones from the last version of the package.
namespace App\Notifications\Concerns;
class FcmMessage extends \NotificationChannels\Fcm\FcmMessage
{
public function toArray(): array
{
$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,
];
if ($token = $this->getToken()) {
$data['token'] = $token;
}
if ($topic = $this->getTopic()) {
$data['topic'] = $topic;
}
if ($condition = $this->getCondition()) {
$data['condition'] = $condition;
}
return $data;
}
}
Then, replace your notifications to use your own FcmMessage like so:
class PushNotification extends Notification
{
// ...
public function toFcm($notifiable)
{
return \App\Notifications\Concerns\FcmMessage::create();
}
// ...
}
=> "A message can only have one of the following targets: condition, token, topic, unknown"
again the same issue generates.
Any news here?
@masterix21 The create function needs to be overridden as well.
namespace App\Notifications\Concerns;
class FcmMessage extends \NotificationChannels\Fcm\FcmMessage
{
public static function create(): self
{
return new self;
}
public function toArray(): Array
{
$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,
];
if ($token = $this->getToken()) {
$data['token'] = $token;
}
if ($topic = $this->getTopic()) {
$data['topic'] = $topic;
}
if ($condition = $this->getCondition()) {
$data['condition'] = $condition;
}
return $data;
}
}
class PushNotification extends Notification
{
// ...
public function toFcm($notifiable)
{
return \App\Notifications\Concerns\FcmMessage::create();
}
// ...
}
Apologies for the delay, I'm not the maintainer of this specific package and had notifications off. I'll merge shortly, if anyone is interested in joining as maintainer please email me.
@atymic - happy to help out with maintenance. I already look after the APN and Facebook channels as well.
https://github.com/kreait/firebase-php/blob/6.x/src/Firebase/Messaging/CloudMessage.php#L75
It checks array keys but does not check if they are empty or not, so it causes "A message can only have one of the following targets: condition, token, topic, unknown" error.