You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?php
namespace App\Notifications;
use Illuminate\Notifications\Notification;
use NotificationChannels\Fcm\FcmChannel;
use NotificationChannels\Fcm\FcmMessage;
use NotificationChannels\Fcm\Resources\AndroidConfig;
use NotificationChannels\Fcm\Resources\AndroidFcmOptions;
use NotificationChannels\Fcm\Resources\AndroidNotification;
use NotificationChannels\Fcm\Resources\ApnsConfig;
use NotificationChannels\Fcm\Resources\ApnsFcmOptions;
class FcmNotification extends Notification
{
/**
* Create a new notification instance.
*
* @return void
*/
public $title;
public $body;
public function __construct($title, $body)
{
$this->title = $title;
$this->body = $body;
}
public function via($notifiable)
{
return [FcmChannel::class];
}
public function toFcm($notifiable)
{
return FcmMessage::create()
// ->setData(['data1' => 'value', 'data2' => 'value2'])
->setNotification(\NotificationChannels\Fcm\Resources\Notification::create()
->setTitle($this->title)
->setBody($this->body)
// ->setImage('http://example.com/url-to-image-here.png')
)
->setAndroid(
AndroidConfig::create()
->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics'))
->setNotification(AndroidNotification::create()->setColor('#0A0A0A'))
)->setApns(
ApnsConfig::create()
->setFcmOptions(ApnsFcmOptions::create()->setAnalyticsLabel('analytics_ios')));
}
// optional method when using kreait/laravel-firebase:^3.0, this method can be omitted, defaults to the default project
public function fcmProject($notifiable, $message)
{
// $message is what is returned by `toFcm`
return 'app'; // name of the firebase project to use
}
}
here is the error message
"message": "A message can only have one of the following targets: condition, token, topic, unknown",
"exception": "NotificationChannels\\Fcm\\Exceptions\\CouldNotSendNotification",
"file": "/var/www/khm-mobile-admin-II/vendor/laravel-notification-channels/fcm/src/Exceptions/CouldNotSendNotification.php",
"line": 13,
"trace": [
{
"file": "/var/www/khm-mobile-admin-II/vendor/laravel-notification-channels/fcm/src/FcmChannel.php",
"line": 84,
"function": "serviceRespondedWithAnError",
"class": "NotificationChannels\\Fcm\\Exceptions\\CouldNotSendNotification",
"type": "::"
},
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello
here is my code
"laravel/framework": "^8.75",
"laravel-notification-channels/fcm": "~2.0",
here is the error message
Beta Was this translation helpful? Give feedback.
All reactions