laravel-notification-channels / fcm Goto Github PK
View Code? Open in Web Editor NEWFirebase Cloud Messaging (FCM) notifications channel for Laravel
Home Page: https://laravel-notification-channels.com/
License: MIT License
Firebase Cloud Messaging (FCM) notifications channel for Laravel
Home Page: https://laravel-notification-channels.com/
License: MIT License
I have done everything fine. its worked two days before. i don't know why its not working now. its saying an error from "vendor/laravel-notification-channels/fcm/src/Exceptions/CouldNotSendNotification.php". and the error is Requested entity was not found.
// The FcmNotification holds the notification parameters
$fcmNotification = FcmNotification::create()
->setTitle('Someone has sent you a friend request')
->setBadge(2);
When I check my iPad, the badge doesn't seem to show up.
Is there a way to set the notification type as mentioned in the FCM docs?
I'm having problems implementing with React Native (expo managed projec) and found a little piece of advice in the expo docs:
Notification messages are only handled (and displayed) by the Firebase library, meaning they won't necessarily wake the app, and expo-notifications will not be made aware that your app has received any notification. (source)
How to handle this?
Unable to catch the exception since all the users may not have a fcm token, also it would be useful to catch invalid token. Any input or suggestions?
I've implemented this package in my app, I also wrote this question on StackOverflow.
Notification works, but it does not gave me all data I needed.
CreatedAgenda.php
return FcmMessage::create()
->setTopic('agenda')
->setData([
'agenda' => $this->agenda,
'data2' => 'hello world!',
'click_action' => 'FLUTTER_NOTIFICATION_CLICK',
])
->setNotification($notification)
->setAndroid($androidConfig)
->setApns($iosConfig);
Debug Console (client side)
I/flutter (31507): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (31507): │ NotificationService: onMessage
I/flutter (31507): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (31507): │ 🐛 {
I/flutter (31507): │ 🐛 "notification": {
I/flutter (31507): │ 🐛 "title": "Agenda Invitation",
I/flutter (31507): │ 🐛 "body": "You've been invited to participate in Wirda's agenda."
I/flutter (31507): │ 🐛 },
I/flutter (31507): │ 🐛 "data": {
I/flutter (31507): │ 🐛 "click_action": "FLUTTER_NOTIFICATION_CLICK"
I/flutter (31507): │ 🐛 }
I/flutter (31507): │ 🐛 }
I/flutter (31507): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
since upgrade to version 2.1 exception started to be thrown
Method getValue not found on class NotificationChannels\Fcm\Resources\AndroidMessagePriority
probably due to update of spatie/enum from 2.3.8 to 3.1.1
laravel 6, rollback to version 2.0.4 solved that issue
How can I send a notification to all users, or maybe send one public notification without a token?
Could somebody provide an example, if it's possible.
Apns not support collapse for group messages, while android support group messages i can't do that for ios.
I need to send apns_collapse_id .How can I do?
Hi peeps, having an issue where FCM is returning "invalid registration" and looking online some people have remedied this by sending the sender id through to FCM.
I can't, however, see a parameter to add this to this library. Is there a way to do this?
Issue
There is an issue regarding the json encoding of the data payload inside the FcmMessage.
When using nested arrays they will be recursively encoded in json which will add extra backslashes on every keyvaluepair which invalidates the JSON obj.
toFcm method
$title = 'title;
$body = 'body;
$priority = FcmMessage::PRIORITY_NORMAL;
$timeToLive = 86400;
$nestedArray = [
'key_1' => 'value_1',
'key_2' => 'value_2'
];
$data = [
'key_0' => 'value_0',
"nestedArray" => $nestedArray
];
$fcmNotification = FcmNotification::create()
->setTitle($title)
->setBody($body);
return FcmMessage::create()
->setPriority($priority)
->setTimeToLive($timeToLive)
->setNotification($fcmNotification)
->setData($data);
Output
{"foreground":true,"from":"680981541020","body":"body.""title":"title","data":{"key_0":"value_0","nestedArray":"{\\"key_1\\":\\"value_1\\",\\"key_2\\":\\"value_2\\"}"}}
Error
This is the exception I got (JSON format)
{
"message": "Invalid JSON payload received. Unknown name "key_1" at 'message.data[1].value': Cannot find field.\nInvalid JSON payload received. Unknown name "key_2" at 'message.data[1].value': Cannot find field.",
"exception": "NotificationChannels\Fcm\Exceptions\CouldNotSendNotification",
"line": 11,
...
}
Hi,
I was implementing FcmChannel on a ShouldQueue notification but got Driver [NotificationChannels\Fcm\FcmChannel] error thrown and the notification was sent to mail and broadcast, but not to FcmChannel.
The error was fixed after removing ShouldQueue implementation from the notification class.
I don't know if this is an issue or should I use different notification classes? one for my queueable channels (email, broadcast) and one for the FcmChannel?
Thanks in advance.
I am getting this error for notification.
I followed all the step. and worked for some of my notification.
return FcmMessage::create()
// ->setData([
// 'status' => $status,
// 'link' => $link,
// 'id' => $id,
// ])
->setNotification(\NotificationChannels\Fcm\Resources\Notification::create()
->setTitle($subject)
->setBody($body)
->setImage($icon));
Hello,
how i can pass priority normal or high in FcmMessage ?
We are trying to send notification to topic but it only sends notification to token and gives error if topic is specified
NotificationChannels\Fcm\Exceptions\CouldNotSendNotification
Invalid value at 'message' (oneof), oneof field 'target' is already set. Cannot set 'topic
if we return empty or null token for a user, it does not send notification at all
I'm trying to send data as follows in sendFcm method;
return FcmMessage::create() ->setData(['type' => 'xxx', 'id' => 21465]) ->setNotification(\NotificationChannels\Fcm\Resources\Notification::create() ->setTitle('a title') ->setBody('a body') ) ->setAndroid(AndroidConfig::create() ->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics')) ->setNotification(AndroidNotification::create()->setColor('#0A0A0A')) ) ->setApns(ApnsConfig::create()->setFcmOptions(ApnsFcmOptions::create()->setAnalyticsLabel('analytics_ios')));
but causing an error;
ERROR: Invalid value at 'message.data[1].value' (TYPE_STRING), 21465 {"exception":"[object] (NotificationChannels\\Fcm\\Exceptions\\CouldNotSendNotification(code: 0): Invalid value at 'message.data[1].value'
how can it be solved?
Hello, i use this library to send notification cloud message, but i get an error when token is old, i mean i try to launch application from my device (react-native) register my new token on laravel and then send notification, and working, on relaunch and re-installetion of appliation and so new registration of token (no refresh - i manage this - but isnew one, so the old is unregisted) i get error near old token that block the execution of script:
NotificationChannels\Fcm\Exceptions\CouldNotSendNotification
Requested entity was not found.
NotificationChannels\Fcm\Exceptions\CouldNotSendNotification::serviceRespondedWithAnError
vendor/laravel-notification-channels/fcm/src/Exceptions/CouldNotSendNotification.php:11
exist a way to fix it? maybe ignore if return an error ? thanks
Hi @atymic,
Not sure why but I always get a notification for this repo to my email. I'm either added by mistake within this project or on Travis CI. I have neither stared nor watching the project. There is no way for me to check or remove myself either. I can see it listed inside my Travis CI account but no way to disable (says "Insufficient permissions").
It would be great if you could please take a look and remove me from this project if I'm added?
Thanks!
Hey guys. I need to send a link with a text that will point to my website after clicking on a notification. What is the best way to do this?
I see that older version of the package support setBadge() but I do not see a way to setBadge in the latest version. Am I missing something?
I have several Firebase projects, hence I have several Firebase private key (firebase_credentials.json files).
How can I use multiple Firebase credentials with this package?
The instruction mention only to add a single firebase_credentials.json in the .env file.
Could you please include also setSound when creating a Notification?
On iOS the notification sound is disabled by default unless we set "sound": "default"
Thank you.
Issue
There is an issue regarding the json encoding of the data payload inside the FcmMessage.
When using nested arrays they will be recursively encoded in json which will add extra backslashes on every keyvaluepair which invalidates the JSON obj.
toFcm method
$title = 'title;
$body = 'body;
$priority = FcmMessage::PRIORITY_NORMAL;
$timeToLive = 86400;
$nestedArray = [
'key_1' => 'value_1',
'key_2' => 'value_2'
];
$data = [
'key_0' => 'value_0',
"nestedArray" => $nestedArray
];
$fcmNotification = FcmNotification::create()
->setTitle($title)
->setBody($body);
return FcmMessage::create()
->setPriority($priority)
->setTimeToLive($timeToLive)
->setNotification($fcmNotification)
->setData($data);
output
{"foreground":true,"from":"680981541020","body":"body.""title":"title","data":{"key_0":"value_0","nestedArray":"{\\"key_1\\":\\"value_1\\",\\"key_2\\":\\"value_2\\"}"}}
Hi,
When anyone could, fix de readme. The method name routeNotificationForFcm was changed for routeNotificationFor .
I'm not open a pull request for this.
Thanks for all! :)
Hi,
I would sugget to change the readme, section install
You have made 2 minor change to the library, 2.0.1 and 2.0.2 that fixes the use with Laravel 7.
Using the command ^2.0 can't download this minor change that are mandatory in a Laravel 7 projet.
I suggest to change the install command to ~2.0 or 2.0.* or something similar, I used:
composer require laravel-notification-channels/fcm:~2.0
I'm not really expert of composer so check it.
You can replicate the issue simply creating a new freshly Laravel 7.x install and running the command.
It will checkout v2.0.0 instead of v2.0.2 and issuing the error:
laravel-notification-channels/fcm 2.0.0 requires illuminate/support ~5.6 || ~6.0
I struggled a bit trying to resolve this.
Hope this helps.
Salvatore D'Alessandro, Italy.
how i can add sound to notification. I have no ssound!
I can't seem to find it anywhere, but does this package support silent notifications?
Dear Contributor,
I am facing a problem with related to sending push. the setData() function works well with static values such as
->setData(['data1' => 'value 1', 'data2' => 'value 2'])
However, in my case these information may be variable. When I am doing like this
$data['title'] = "Some title";
$data['body'] = "Some message";
and then passing this
->setData($data);
then notification does not come. How to format it so it will appear in Browser and mobile app client so they can handle the same.
Thanks in advance.
I'm using Lumen instead of Laravel. And by default the facade is disabled. Now, if I just want to use this package to send a notification, do I have to enable facade? I searched in https://laravel-notification-channels.com/fcm/#usage and your doc for Facade and Lumen, didn't show up any result. But the marked code is imported from the facade namespace.
Would you consider changing it to app()
? Why force developer to use facade while it can be avoided? Even the https://github.com/kreait/laravel-firebase package didn't even force to use.
Line 108 in 8b95cd0
I need to send notifications to all my users. i dont know how to do it. could you please share me some reference because i couldn't see any documents for this.
When composer auto-upgraded to 2.1.2, notifications on a queue stopped working with this exception:
Illuminate\Contracts\Container\BindingResolutionException: Target [Kreait\Firebase\Project\ProjectId] is not instantiable while building [NotificationChannels\Fcm\FcmChannel, Kreait\Firebase\Messaging].
Downgrading to 2.1.1 solves the problem.
hi I got an error in previous days from this module here is the code and screenshot, please I need help to resolve this issue.
error is SenderId mismatch
I create two SHA 1 Keys one for development and the second one is for production.
Also, I change my SHA 1 key from the google developer account for the google play store uploaded file.
any problems with the above changes in the project?
$title = 'My Notification Title';
$body = 'My Notification Body';
$notification = Notification::fromArray([
'title' => $title,
'body' => $body,
]);
$notification = Notification::create($title, $body);
$messaging = app('firebase.messaging');
$deviceToken = 'i add my token here.....';
$message = CloudMessage::withTarget('token', $deviceToken)->withNotification($notification); // optional;
$message = CloudMessage::fromArray([
'token' => $deviceToken
]);
try {
...
$messaging->send($message);
} catch (\Kreait\Firebase\Exception\MessagingException $e) {
dd($e->errors());
}
How do we set priorities? also, I couldn't find how to set Icon for web push notification.
Thanks in advance, and awesome work!
Why i always get empty result of routeNotificationForFcm() function from User model?
Which background algorithm getting the FCM? Cant understand...
Hi! I have problem when implementing this package. I'm sure I have followed the instruction properly. No idea what causing this.
stackTrace
{
"message": "Call to a member function routeNotificationFor() on int",
"exception": "Error",
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel-notification-channels/fcm/src/FcmChannel.php",
"line": 33,
"trace": [
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php",
"line": 148,
"function": "send",
"class": "NotificationChannels\Fcm\FcmChannel",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php",
"line": 106,
"function": "sendToNotifiable",
"class": "Illuminate\Notifications\NotificationSender",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Support/Traits/Localizable.php",
"line": 19,
"function": "Illuminate\Notifications\{closure}",
"class": "Illuminate\Notifications\NotificationSender",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php",
"line": 109,
"function": "withLocale",
"class": "Illuminate\Notifications\NotificationSender",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php",
"line": 79,
"function": "sendNow",
"class": "Illuminate\Notifications\NotificationSender",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Notifications/ChannelManager.php",
"line": 39,
"function": "send",
"class": "Illuminate\Notifications\NotificationSender",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php",
"line": 261,
"function": "send",
"class": "Illuminate\Notifications\ChannelManager",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/app/Http/Controllers/API/V1/AgendaController.php",
"line": 74,
"function": "__callStatic",
"class": "Illuminate\Support\Facades\Facade",
"type": "::"
},
{
"function": "store",
"class": "App\Http\Controllers\API\V1\AgendaController",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Routing/Controller.php",
"line": 54,
"function": "call_user_func_array"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php",
"line": 45,
"function": "callAction",
"class": "Illuminate\Routing\Controller",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
"line": 255,
"function": "dispatch",
"class": "Illuminate\Routing\ControllerDispatcher",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
"line": 197,
"function": "runController",
"class": "Illuminate\Routing\Route",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 691,
"function": "run",
"class": "Illuminate\Routing\Route",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 128,
"function": "Illuminate\Routing\{closure}",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php",
"line": 41,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Routing\Middleware\SubstituteBindings",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php",
"line": 127,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php",
"line": 103,
"function": "handleRequest",
"class": "Illuminate\Routing\Middleware\ThrottleRequests",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php",
"line": 55,
"function": "handleRequestUsingNamedLimiter",
"class": "Illuminate\Routing\Middleware\ThrottleRequests",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Routing\Middleware\ThrottleRequests",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php",
"line": 44,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Auth\Middleware\Authenticate",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/sanctum/src/Http/Middleware/EnsureFrontendRequestsAreStateful.php",
"line": 33,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 128,
"function": "Laravel\Sanctum\Http\Middleware\{closure}",
"class": "Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 103,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/sanctum/src/Http/Middleware/EnsureFrontendRequestsAreStateful.php",
"line": 34,
"function": "then",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 167,
"function": "handle",
"class": "Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 103,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 693,
"function": "then",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 668,
"function": "runRouteWithinStack",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 634,
"function": "runRoute",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 623,
"function": "dispatchToRoute",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line": 166,
"function": "dispatch",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 128,
"function": "Illuminate\Foundation\Http\{closure}",
"class": "Illuminate\Foundation\Http\Kernel",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
"line": 21,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\TransformsRequest",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
"line": 21,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\TransformsRequest",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php",
"line": 27,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\ValidatePostSize",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php",
"line": 87,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/fruitcake/laravel-cors/src/HandleCors.php",
"line": 57,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 167,
"function": "handle",
"class": "Fruitcake\Cors\HandleCors",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/fideloper/proxy/src/TrustProxies.php",
"line": 57,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 167,
"function": "handle",
"class": "Fideloper\Proxy\TrustProxies",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 103,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line": 141,
"function": "then",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line": 110,
"function": "sendRequestThroughRouter",
"class": "Illuminate\Foundation\Http\Kernel",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/public/index.php",
"line": 66,
"function": "handle",
"class": "Illuminate\Foundation\Http\Kernel",
"type": "->"
},
{
"file": "/Users/warmachine/Documents/Programming/Laravel/censoredprojectname/server.php",
"line": 21,
"function": "require_once"
}
]
}
implementation
<?php
namespace App\Notifications;
use App\Models\Agenda;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
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;
use NotificationChannels\Fcm\Resources\Notification as ResourcesNotification;
class AgendaCreated extends Notification
{
use Queueable;
public $agenda;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Agenda $agenda)
{
$this->agenda = $agenda;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return [FcmChannel::class];
}
/**
* Get the fcm representation of the notification.
*
* @param mixed $notifiable
* @return \NotificationChannels\Fcm\FcmMessage
*/
public function toFcm($notifiable)
{
$author = $this->agenda->author->name;
return FcmMessage::create()
->setToken($notifiable->fcm_token)
->setTopic('agenda')
->setNotification(
ResourcesNotification::create()
->setTitle('New agenda invitation!')
->setBody('You\'ve been invited to participate in ' . $author . '\'s agenda. Tap here to see in details.')
)
->setAndroid(
AndroidConfig::create()
->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics'))
->setNotification(AndroidNotification::create()->setColor('#0A0A0A'))
)
->setApns(
ApnsConfig::create()
->setFcmOptions(ApnsFcmOptions::create()->setAnalyticsLabel('analytics_ios'))
);
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
model implementation
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
use HasFactory, HasApiTokens, Notifiable, HasRoles;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'avatar',
'name',
'email',
'password',
'fcm_token',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token', // 'pivot',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
/**
* Specifies the user's FCM token
*
* @return string
*/
public function routeNotificationForFcm()
{
return $this->fcm_token;
}
...
I am using kreait/laravel-firebase:^2.1
in my project and whenever I try to composer require laravel-notification-channels/fcm
I get an error because of the dependency version defined in the package composer.json
Here is what I get when I run:
composer require laravel-notification-channels/fcm:^2.0
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for laravel-notification-channels/fcm ^2.0 -> satisfiable by laravel-notification-channels/fcm[2.0.0, 2.0.1, 2.0.2].
- Can only install one of: kreait/laravel-firebase[1.x-dev, 2.1.0].
- Can only install one of: kreait/laravel-firebase[1.x-dev, 2.1.0].
- Can only install one of: kreait/laravel-firebase[1.x-dev, 2.1.0].
- Conclusion: install kreait/laravel-firebase 1.x-dev
- Installation request for kreait/laravel-firebase ^2.1 -> satisfiable by kreait/laravel-firebase[2.1.0].
Installation failed, reverting ./composer.json to its original content.
And this is what I get if I didn't specify the version:
composer require laravel-notification-channels/fcm
Using version ^2.0 for laravel-notification-channels/fcm
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for laravel-notification-channels/fcm ^2.0 -> satisfiable by laravel-notification-channels/fcm[2.0.0, 2.0.1, 2.0.2].
- Can only install one of: kreait/laravel-firebase[1.x-dev, 2.1.0].
- Can only install one of: kreait/laravel-firebase[1.x-dev, 2.1.0].
- Can only install one of: kreait/laravel-firebase[1.x-dev, 2.1.0].
- Conclusion: install kreait/laravel-firebase 1.x-dev
- Installation request for kreait/laravel-firebase ^2.1 -> satisfiable by kreait/laravel-firebase[2.1.0].
Installation failed, reverting ./composer.json to its original content.
I am not sure what should be the appropriate solution here, should we allow version 2.1.0
for laravel-firebase
in the composer.json file of the package?
I can open a PR for this fix if that would solve this issue.
How can I know which tokens failed to send message
Suppose, the user has multiple devices. So i have multiple tokens of a user. How can I send notifications to all of his devices?
I've my listener setup
`<?php
namespace App\Listeners;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Events\NotificationSent;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
class LogNotification
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param NotificationSent $event
* @return void
*/
public function handle(NotificationSent $event)
{
Log::info($event->response);
}
}`
but I've nit been able to capture failed tokens.
Anyone have an idea on how to capture failed tokens, kindly assist.
Laravel 8 has been released today and we need to update this repo to support it.
See https://laravel.com/docs/8.x/upgrade & laravel-notification-channels/channels#107
How do we handle multiple FCM tokens for a single user?
I need to pass some data to my notification class but when i use a constructor with parameters, the notification is not sent.
No error shown and others channels like database still working normally
I build a mobile social network and I want to update the number of likes of a post using a push notification. But I don't want the users to be disturbed each time a post is liked when the app is in background. So is there a way to tell the mobile app to receive notification only when the app is in foreground?
Thanks
I have put everything correct according to steps to use this,but still I am getting this error. I dont know how to resove it
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.