kreait / laravel-firebase Goto Github PK
View Code? Open in Web Editor NEWA Laravel package for the Firebase PHP Admin SDK
Home Page: https://github.com/kreait/firebase-php
License: MIT License
A Laravel package for the Firebase PHP Admin SDK
Home Page: https://github.com/kreait/firebase-php
License: MIT License
// MyNotification.php
public function toFcm($notifiable)
{
return CloudMessage::fromArray([
'notification' => [
'body' => 'This is an FCM notification message!',
'title' => 'FCM Message',
],
'data' => [
'foo' => 'bar',
],
'android' => [
'ttl' => '3600s',
'notification' => [
'icon' => 'stock_ticker_update',
'color' => '#f45342',
],
],
'apns' => [
'payload' => [
'aps' => [
'badge' => 100,
],
],
],
]);
}
// FcmChannel.php
namespace App\Channels;
use Illuminate\Notifications\Notification;
use Kreait\Laravel\Firebase\Facades\FirebaseMessaging;
class FcmChannel
{
/**
* Send the given notification.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return void
*/
public function send($notifiable, Notification $notification)
{
$message = $notification->toFcm($notifiable);
FirebaseMessaging::sendMulticast($message, $notifiable->routeNotificationFor('fcm', $notification));
}
}
Get an error:
[2020-02-02 10:11:40] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Class 'Kreait\Firebase\Messaging\RawMessageFromArray' not found in /home/vagrant/Code/lumen/vendor/kreait/firebase-php/src/Firebase/Messaging/Http/Request/SendMessageToTokens.php:36
we failsKreait\Firebase\Exception\InvalidArgumentException: json_decode error: Syntax error in C:\wamp64\www\meshwari68\vendor\kreait\firebase-php\src\Firebase\Util\JSON.php:63 Stack trace: #0 C:\wamp64\www\meshwari68\vendor\kreait\firebase-php\src\Firebase\Database\ApiClient.php(47): Kreait\Firebase\Util\JSON::decode('...', true) #1 C:\wamp64\www\meshwari68\vendor\kreait\firebase-php\src\Firebase\Database\Reference.php(282): Kreait\Firebase\Database\ApiClient->get(Object(GuzzleHttp\Psr7\Uri)) #2 C:\wamp64\www\meshwari68\vendor\kreait\firebase-php\src\Firebase\Database\Reference.php(247): Kreait\Firebase\Database\Reference->getSnapshot() #3 C:\wamp64\www\meshwari68\app\Http\Controllers\Api\Traits\NotificationTrait.php(266): Kreait\Firebase\Database\Reference->getValue() #4 C:\wamp64\www\meshwari68\app\Http\Controllers\Api\Traits\NotificationTrait.php(93): App\Jobs\SendNotifiNewOrders->sendNotification(Array, Array) #5 C:\wamp64\www\meshwari68\app\Jobs\SendNotifiNewOrders.php(49): App\Jobs\SendNotifiNewOrders->generateNotification('FCMToAllDrivers', 165, NULL, NULL, NULL) #6 [internal function]: App\Jobs\SendNotifiNewOrders->handle() #7 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(32): call_user_func_array(Array, Array) #8 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Container\Util.php(36): Illuminate\Container\BoundMethod::Illuminate\Container{closure}() #9 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(90): Illuminate\Container\Util::unwrapIfClosure(Object(Closure)) #10 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure)) #11 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Container\Container.php(590): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL) #12 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(94): Illuminate\Container\Container->call(Array) #13 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(130): Illuminate\Bus\Dispatcher->Illuminate\Bus{closure}(Object(App\Jobs\SendNotifiNewOrders)) #14 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(105): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(App\Jobs\SendNotifiNewOrders)) #15 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure)) #16 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(83): Illuminate\Bus\Dispatcher->dispatchNow(Object(App\Jobs\SendNotifiNewOrders), false) #17 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(130): Illuminate\Queue\CallQueuedHandler->Illuminate\Queue{closure}(Object(App\Jobs\SendNotifiNewOrders)) #18 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(105): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(App\Jobs\SendNotifiNewOrders)) #19 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(85): Illuminate\Pipeline\Pipeline->then(Object(Closure)) #20 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(59): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware(Object(Illuminate\Queue\Jobs\SyncJob), Object(App\Jobs\SendNotifiNewOrders)) #21 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(88): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\SyncJob), Array) #22 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Queue\SyncQueue.php(45): Illuminate\Queue\Jobs\Job->fire() #23 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Queue\SyncQueue.php(151): Illuminate\Queue\SyncQueue->push(Object(App\Jobs\SendNotifiNewOrders), '', NULL) #24 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(179): Illuminate\Queue\SyncQueue->later(Object(Illuminate\Support\Carbon), Object(App\Jobs\SendNotifiNewOrders)) #25 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(158): Illuminate\Bus\Dispatcher->pushCommandToQueue(Object(Illuminate\Queue\SyncQueue), Object(App\Jobs\SendNotifiNewOrders)) #26 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(73): Illuminate\Bus\Dispatcher->dispatchToQueue(Object(App\Jobs\SendNotifiNewOrders)) #27 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Foundation\Bus\PendingDispatch.php(112): Illuminate\Bus\Dispatcher->dispatch(Object(App\Jobs\SendNotifiNewOrders)) #28 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php(392): Illuminate\Foundation\Bus\PendingDispatch->__destruct() #29 C:\wamp64\www\meshwari68\app\Http\Controllers\Api\CustomerRideController.php(211): dispatch(Object(App\Jobs\SendNotifiNewOrders)) #30 [internal function]: App\Http\Controllers\Api\CustomerRideController->orderRide(Object(App\Http\Requests\BookingServiceRequest)) #31 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Routing\Controller.php(54): call_user_func_array(Array, Array) #32 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction('orderRide', Array) #33 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Routing\Route.php(219): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(App\Http\Controllers\Api\CustomerRideController), 'orderRide') #34 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Routing\Route.php(176): Illuminate\Routing\Route->runController() #35 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Routing\Router.php(681): Illuminate\Routing\Route->run() #36 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(130): Illuminate\Routing\Router->Illuminate\Routing{closure}(Object(Dingo\Api\Http\Request)) #37 C:\wamp64\www\meshwari68\vendor\tymon\jwt-auth\src\Http\Middleware\Authenticate.php(40): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Dingo\Api\Http\Request)) #38 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Tymon\JWTAuth\Http\Middleware\Authenticate->handle(Object(Dingo\Api\Http\Request), Object(Closure)) #39 C:\wamp64\www\meshwari68\app\Http\Middleware\AssignGuard.php(24): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Dingo\Api\Http\Request)) #40 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): App\Http\Middleware\AssignGuard->handle(Object(Dingo\Api\Http\Request), Object(Closure), 'rides') #41 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Routing\Middleware\SubstituteBindings.php(41): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Dingo\Api\Http\Request)) #42 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Dingo\Api\Http\Request), Object(Closure)) #43 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Routing\Middleware\ThrottleRequests.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Dingo\Api\Http\Request)) #44 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Illuminate\Routing\Middleware\ThrottleRequests->handle(Object(Dingo\Api\Http\Request), Object(Closure), 60, '1') #45 C:\wamp64\www\meshwari68\vendor\dingo\api\src\Http\Middleware\PrepareController.php(45): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Dingo\Api\Http\Request)) #46 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Dingo\Api\Http\Middleware\PrepareController->handle(Object(Dingo\Api\Http\Request), Object(Closure)) #47 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(105): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Dingo\Api\Http\Request)) #48 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Routing\Router.php(683): Illuminate\Pipeline\Pipeline->then(Object(Closure)) #49 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Routing\Router.php(658): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Dingo\Api\Http\Request)) #50 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Routing\Router.php(624): Illuminate\Routing\Router->runRoute(Object(Dingo\Api\Http\Request), Object(Illuminate\Routing\Route)) #51 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Routing\Router.php(613): Illuminate\Routing\Router->dispatchToRoute(Object(Dingo\Api\Http\Request)) #52 C:\wamp64\www\meshwari68\vendor\dingo\api\src\Routing\Adapter\Laravel.php(88): Illuminate\Routing\Router->dispatch(Object(Dingo\Api\Http\Request)) #53 C:\wamp64\www\meshwari68\vendor\dingo\api\src\Routing\Router.php(518): Dingo\Api\Routing\Adapter\Laravel->dispatch(Object(Dingo\Api\Http\Request), 'v1') #54 C:\wamp64\www\meshwari68\vendor\dingo\api\src\Http\Middleware\Request.php(126): Dingo\Api\Routing\Router->dispatch(Object(Dingo\Api\Http\Request)) #55 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(130): Dingo\Api\Http\Middleware\Request->Dingo\Api\Http\Middleware{closure}(Object(Dingo\Api\Http\Request)) #56 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Dingo\Api\Http\Request)) #57 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Dingo\Api\Http\Request), Object(Closure)) #58 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Dingo\Api\Http\Request)) #59 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Dingo\Api\Http\Request), Object(Closure)) #60 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Dingo\Api\Http\Request)) #61 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(Object(Dingo\Api\Http\Request), Object(Closure)) #62 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php(63): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Dingo\Api\Http\Request)) #63 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Dingo\Api\Http\Request), Object(Closure)) #64 C:\wamp64\www\meshwari68\vendor\fideloper\proxy\src\TrustProxies.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Dingo\Api\Http\Request)) #65 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Fideloper\Proxy\TrustProxies->handle(Object(Dingo\Api\Http\Request), Object(Closure)) #66 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(105): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Dingo\Api\Http\Request)) #67 C:\wamp64\www\meshwari68\vendor\dingo\api\src\Http\Middleware\Request.php(127): Illuminate\Pipeline\Pipeline->then(Object(Closure)) #68 C:\wamp64\www\meshwari68\vendor\dingo\api\src\Http\Middleware\Request.php(103): Dingo\Api\Http\Middleware\Request->sendRequestThroughRouter(Object(Dingo\Api\Http\Request)) #69 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Dingo\Api\Http\Middleware\Request->handle(Object(Dingo\Api\Http\Request), Object(Closure)) #70 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(105): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request)) #71 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(145): Illuminate\Pipeline\Pipeline->then(Object(Closure)) #72 C:\wamp64\www\meshwari68\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(110): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request)) #73 C:\wamp64\www\meshwari68\index.php(55): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request)) #74 {main}{"message":"json_decode error: Syntax error","status_code":500}
I usually have a queued job to process sending a push notification. When the job gets a ServerError
or ServerUnavailable
Exception, it will retry immediately until it runs out of the number of tries.
Ideally, if the job gets the ServerError
or ServerUnavailable
. It should wait for 30s before trying again. I am not sure how to do this? Any suggestions?
In the php docs it talks about adding withEnabledDebug() to the factory, is there a way to do this in the laravel wrapper?
Can
you please let me know on subscription why I am getting permission denied error. While I am using Facades now instead of the factory.
Here is an example of a sample code that I am using. Correct me if I am doing something wrong.
I have assigned false validation rule on firebase because authentication is required there and how can I do authentication to using the admin-firebase laravel package. However, I didn't do any authentication when using a factory and it was working. One another thing, do we have support to use understand-delivery with that package?
Code:
use FirebaseMessaging, FirebaseDatabase;
FirebaseMessaging::unsubscribeFromTopic($topic, $tokensArray);
Hello, i am able to send a message via laravel to my app but when in the bg the notification is the default silent notification. My notification is on high but nothing changes.
$deviceToken = 'fSQJb3T1tsg:APA91bFN80J7kJSd0S-lSHfpk8pHCo7EQc38rA7ymK4';
//FIX_THIS_SOON
//remove this later
$notificationTitle = 'Package is being delivered';
// $notificationBody = 'Your order 9847GH8409 is on it\'s way to you.'; //version 1
// $notificationBody = 'Your order 9847GH8419 is on it\'s way to you.'; //version 2
$notificationBody = 'Your order 9847GH8428 is on its way to you.'; //version 3
$notificationIcon = 'http://lorempixel.com/400/200/'; //
$notificationImageUrl = 'http://lorempixel.com/400/200/';
$notificationPriority = 'high';
/* $notification = Notification::fromArray([
'title' => $notificationTitle,
'body' => $notificationBody,
// 'image' => $imageUrl,
]); */
// $notification = Notification::create($notificationTitle, $notificationBody);
// https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notification
$notificationPayload = [
'title' => $notificationTitle,
'body' => $notificationBody,
//'image' => 'http://lorempixel.com/400/200/',
];
$data = [
'click_action' => 'FLUTTER_NOTIFICATION_CLICK',
'action' => 'new_notification',
'notification_id' => '888888888',
'notification_uid' => '1111-2222-3333-4444',
'notification_foreignUID' => '5555-6666-7777-8888',
'notification_foreignUID_type' => 'user',
'notification_title' => $notificationTitle,
'notification_message' => $notificationBody,
'notification_asset_type' => 'image',
'notification_image' => 'http://127cf52a.ngrok.io/storage/images_products/860a6ac4-bd66-4c3b-b07f-450f7cdcc007_2020-01-20_15-15-21_0001.jpg',
'notification_icon' => null,
'notification_account_type' => 'client',
'notification_read_status' => '0',
'notification_status' => 'active',
'notification_created_at' => '2020-03-29 02:09:00',
'notification_updated_at' => '2020-03-29 02:09:00',
];
// https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#androidconfig
$androidSettings = [
'ttl' => '3600s',
'priority' => $notificationPriority,
'notification' => [
'title' => $notificationTitle,
'body' => $notificationBody,
// 'icon' => 'stock_ticker_update', //optional
// 'color' => '#f45342', //optional
],
];
// https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#apnsconfig
$apnsSettings = [
'headers' => [
'apns-priority' => '10',
],
'payload' => [
'aps' => [
'alert' => [
'title' => $notificationTitle,
'body' => $notificationBody,
],
'badge' => 42,
],
],
];
// https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#webpushconfig
$webpushSettings = [
'notification' => [
'title' => $notificationTitle,
'body' => $notificationBody,
// 'icon' => $notificationIcon, //optional
],
];
//hide fcm_options if you are leaving it empty
// https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#fcmoptions
$fcmOptions = [
'analytics_label' => 'some-analytics-label' //optional
];
$message = new RawMessageFromArray([
'token' => $deviceToken,
'notification' => $notificationPayload,
'data' => $data,
'android' => $androidSettings,
'apns' => $apnsSettings,
'webpush' => $webpushSettings,
'fcm_options' => $fcmOptions
]);
$messaging = app('firebase.messaging');
$messaging->send($message);
Hi,
I'm trying to use this package but I get this error:
Kreait\Firebase\Exception\InvalidArgumentException
google-service-account.json can not be read: SplFileObject::__construct(google-service-account.json):
failed to open stream: No such file or directory
I set the firebase service account json path in the env file in this way
FIREBASE_CREDENTIALS=google-service-account.json
and
FIREBASE_CREDENTIALS=/google-service-account.json
but it doesn't work, I'm trying to run this code in a HTTP Controller class
FirebaseAuth::listUsers();
The google-service-account.json file is in the Laravel project root folder along with composer.json etc.
What's the issue ?
Thanks
UPDATE: I'm on windows 10 and if I give the full path like so
FIREBASE_CREDENTIALS="C:\\xampp\\htdocs\\my-laravel-app\\google-service-account.json"
It works, how do I make it work with relative path ?
Our app developer is asking for content_available:true to be outside of the ->withData() array. Is there a way to do this or should we create a raw message array?
I successfully created the service account and am using automatic detection of the .json file download from firebase.
I can validate the tokens generated and get the expected results when I invoke the method through php artisan command, but when I invoke the method with the POST request, I get the exception message bellow, kindly help me because I used the Artisan commands just to test my integration.
Kreait\Firebase\ServiceAccount\Discovery\FromEnvironmentVariable: The environment variable "FIREBASE_CREDENTIALS" points to "firebase/noregrets-app-firebase-adminsdk-gyz53-b5fe293de1.json", but has errors: Invalid service account specification Kreait\Firebase\ServiceAccount\Discovery\FromEnvironmentVariable: The environment variable "GOOGLE_APPLICATION_CREDENTIALS" is not set. Kreait\Firebase\ServiceAccount\Discovery\FromGoogleWellKnownFile: The well known file is not readable or invalid cURL error 6: Could not resolve host: metadata.google.internal (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) {"exception":"[object] (Kreait\\Firebase\\Exception\\ServiceAccountDiscoveryFailed(code: 0): Kreait\\Firebase\\ServiceAccount\\Discovery\\FromEnvironmentVariable: The environment variable \"FIREBASE_CREDENTIALS\" points to \"firebase/noregrets-app-firebase-adminsdk-gyz53-b5fe293de1.json\", but has errors: Invalid service account specification Kreait\\Firebase\\ServiceAccount\\Discovery\\FromEnvironmentVariable: The environment variable \"GOOGLE_APPLICATION_CREDENTIALS\" is not set. Kreait\\Firebase\\ServiceAccount\\Discovery\\FromGoogleWellKnownFile: The well known file is not readable or invalid
Expected results when converted to json:
{"application":"webpush","authorizedEntity":"555594871987","platform":"BROWSER"}
This is the method that validates the token:
`public static function validateToken(string $token)
{
$messaging = (new Factory())->createMessaging();
try {
$appInstance = $messaging->getAppInstance($token);
return $appInstance->rawData();
} catch (FirebaseException $e) {
Log::alert($e->getMessage());
return false;
}
}`
This is how I invoke the method with artisan command in routes/console.php file:
`Artisan::command('validate-token', function () {
$token = $this->ask('Enter device token');
$res = FirebaseApp::validateToken($token);
$this->comment(json_encode($res));
})->describe('Validate fcm token test');`
This is how I invoke the method with a post request in my controller file:
`public function fcmToken(Request $request)
{
$token = $request->get("fcm_token");
//Validate token
$raw_data = FirebaseApp::validateToken($token);
if (!$raw_data) {
return response()->json("Invalid registration token");
}
}`
I Searched in kreait\firebase-php package i found it use Kreait\Firebase\Factory
in IntegerationTestCase
class and used it to test. (For example test subscriteToTopic
method in FirebaseMessaging
class).
Is it possible to adding fake
method to FirebaseMessaging
facade and other facades for mocking and used it in test like MailFake
class in laravel.
Example change in FirebaseMessaging
facade:
/**
* @see \Kreait\Firebase\Messaging
*/
final class FirebaseMessaging extends Facade
{
/**
* Replace the bound instance with a fake.
*
* @return \Illuminate\Support\Testing\Fakes\MailFake
*/
public static function fake()
{
static::swap($fake = (new FirebaseFactory())->createMessaging());
return $fake;
}
protected static function getFacadeAccessor()
{
return 'firebase.messaging';
}
}
Example test for an API:
/** @test */
public function subscribe_temp_topic()
{
FirebaseMessaging::fake();
$body = [
'topic' => 'temp',
'fcmToken' => 'token'
];
$this->post('/subscribe', $body, $this->defaultHeaders)
->seeStatusCode(200)
->seeJsonContains([
"results" => [[]]
]);
}
I test and it work prefect. Is it good way for creating test??
I am new to cloud firestore. I am looking for a similar way in php like in javascript to login user and get access to database. I am reffereing to the following code but need that code in php.
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
});
also I have the following rules setup on the firestore database.
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
}
}
Any help will higly be appriciated!
Hello I'm using this via ajax :
`
public function fcmSendMessageToAll(Request $request)
{
$firebaseInstance = new FirebaseInstance();
//$title,$body,$imageUrl
if ($request->input('title')==null || $request->input('body')==null){
throw new InvalidArgumentException("Le champ titre ou texte est vide");
}
$firebaseUserRepository = new FirebaseUserRepo();
try {
$allUsers = $firebaseUserRepository->getAll();
}catch (\Exception $exception){
dd('erreur : '.$exception->getMessage());
}
$arrayTokens = array();
foreach ($allUsers as $key => $firebaseUser) {
if($firebaseUser->getToken() != null){
echo 'token : '.$firebaseUser->getToken().PHP_EOL;
$arrayTokens[] = $firebaseUser->getToken();
}
}
//dd($arrayTokens);//test
if (count($arrayTokens)>0){
//$messaging = (new Firebase\Factory())->createMessaging();
$messaging = $firebaseInstance->factory->createMessaging();
$message = CloudMessage::new();
$notification = Notification::fromArray([
'title' => $request->input('title'),
'body' => $request->input('body'),
'image' => $request->input('imageurl'),
]);
$message->withNotification($notification);
try {
$report = $messaging->sendMulticast($message, $arrayTokens);
echo 'Successful sends: '.$report->successes()->count().PHP_EOL;
}catch(Firebase\Exception\MessagingException $messagingException){
echo 'Failed sends: '.$report->failures()->count().PHP_EOL;
dd('erreur : '.$messagingException->getMessage());
}
if ($report->hasFailures()) {
foreach ($report->failures()->getItems() as $failure) {
echo $failure->error()->getMessage().PHP_EOL;
}
}
}
}
`
unfortunately it says "successful sends : 1" (I've got just one test user with token) but no notification is in the firebase console or received on my phone ?
Do you see where is my error or is it a bug ? Thanks.
Whenever you send "Fieldname" => "value".
It will take as string
So if we want to send "Fieldname" => "reference to document"
Then also, it takes as string
Further, we want to datatype inside the array.
ex: "Fieldname" => array('reference to document")
Please help.
Hey there,
for my current project I need the ability to send FCM to hundreds of different apps. However, as far as I can see there is no way to do so with this package, because you can only set one single configuration?
Using the Firebase admin SDK for PHP, it works like this:
$factory = (new Factory)->withServiceAccount('/path/to/firebase_credentials.json');
Take this as a feature request then, thanks!
How can call CollapseKey function in laravel fcm integration
Hello,
I have an existing Laravel API that currently uses standard JWT to authenticate users. I'm trying to add Google and Twitter SignIn functionality using this Firebase library, and I'm having trouble understanding the methods which I would use to create a user using third party signin. I am looking at the linkProviderThroughAccessToken in the Auth.php file, but I am still not understanding how I would initially create a user using the third party providers. Any help would be greatly appreciated!
Hi, I am trying to test my endpoints protected by firebase authentication, does your package offer an example for use in testing environments? Sorry if I haven't done enough research.
Hello,
I'm trying to get the additionalUserInfo object, in order to retrieve twitter username, to appear in the UserRecord using $this->auth->getUser($uid), and can't seem to find any way to do this. Is it possible with this package?
Thank so much, your help is greatly appreciated.
I want to fetch records using geolocation. is there any way to query using geolocation. please help me to resolve this issue.
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());
}
Is it possible to create a custom client with different credentials?
I would like to store multiple Firebase credentials and instantiate a different client depending on business logic.
Scenario:
Send push notification to APP X using Credentials X and then send push notification to APP Y using Credentials Y.
Am I better off just constructing the cURL myself?
Hello.
This library is very easy to use. I thank you.
It's working is 2 days ago.
Not working today.
I don't change files .env
and firebase_credential.json
.
Please let me know if you have any cause.
error message:
Kreait\Firebase\Exception\RuntimeException : Unable to create a FirestoreClient: Error rendering 'projects/{project=*}/databases/{database=*}': expected binding 'project' to match segment '{project=*}', instead got null
Provided bindings: Array
(
[project] =>
[database] => (default)
)
at /home/mirasapo_admin/wordpress/src/laravel/vendor/kreait/firebase-php/src/Firebase/Factory.php:350
346|
347| try {
348| return new FirestoreClient($config);
349| } catch (Throwable $e) {
> 350| throw new RuntimeException('Unable to create a FirestoreClient: '.$e->getMessage(), $e->getCode(), $e);
351| }
352| }
353|
354| public function createStorage(array $storageClientConfig = null): Storage
Version:
...
google/auth v1.6.1 Google Auth Library for PHP
google/cloud-core v1.34.0 Google Cloud PHP shared dependency, providing functionality useful to all components.
google/cloud-firestore v1.10.0 Cloud Firestore client for PHP
google/cloud-storage v1.16.0 Cloud Storage Client for PHP
google/common-protos 1.1 Google API Common Protos for PHP
google/crc32 v0.1.0 Various CRC32 implementations
google/gax 1.2.0 Google API Core for PHP
google/grpc-gcp 0.1.4 gRPC GCP library for channel management
google/protobuf v3.11.1 proto library for PHP
grpc/grpc 1.25.0 gRPC library for PHP
...
kreait/clock 1.0.1 A PHP 7.0 compatible clock abstraction
kreait/firebase-php 4.36.2 Firebase Admin SDK
kreait/firebase-tokens 1.9.2 A library to work with Firebase tokens
kreait/gcp-metadata 1.0.1 Get the metadata from a Google Cloud Platform environment.
kreait/laravel-firebase 1.2.0 A Laravel package for the Firebase PHP Admin SDK
...
I am getting this error. previously it's working fine. I am using a firebase realtime database
Kreait\Firebase\Exception\Database\ApiConnectionFailed Unable to connect to the API: Connection refused for URI https://oauth2.googleapis.com/token
what is the possible problem?
Hello!
When I try to sen multiple message with sendMulticast from Kreait\Firebase\Messaging I recive an exception - _Unsupported message type. Use an array or a class implementing %sKreait\Firebase\Messaging\Message, despite the fact that I use CloudMessage or Notification.
use Kreait\Firebase\Messaging;
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Firebase\Messaging\Message;
use Kreait\Firebase\Messaging\Notification;
.....
$message = [
'title' => __('mobile_notifications_messages.posts.' . $eventName, [
$author,
$post->title,
]),
'body' => 'Something'
];
$message = Notification::fromArray($message);
$response = $this->messaging->sendMulticast($message, $deviceTokens);
I use Laravel 5.8
Could you please help me with this?
I am facing a issue with this package. Notification are showing it correctly processing but neither it coming in firebase notification list nor reaching the devices.
my test code is below
<?php
$messaging = app('firebase.messaging');
$title = 'My Notification Title';
$body = 'My Notification Body';
// $imageUrl = 'http://lorempixel.com/400/200/';
$notification = Notification::fromArray([
'title' => $title,
'body' => $body,
// 'image' => $imageUrl,
]);
$notification = Notification::create($title, $body);
$changedNotification = $notification
->withTitle('Changed title')
->withBody('Changed body');
// ->withImageUrl('http://lorempixel.com/200/400/');
//return $notification;
$topic = 'a-topic';
$message = CloudMessage::withTarget('topic', $topic)
->withNotification($notification) // optional
//->withData($data) // optional
;
$messaging->send($message);
Hi,
I tried to install this package but it cause me out of memory. I already change the size of my memory_limit in php to -1 but still I've got this error. Please let me know if I miss something before installation.
$ php artisan --version
Laravel Framework Lumen (5.8.12) (Laravel Components 5.8.*)
Thank you.
$ composer require kreait/laravel-firebase
Using version ^2.0 for kreait/laravel-firebase
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
VirtualAlloc() failed: [0x00000008] Not enough memory resources are available to process this command.
VirtualFree() failed: [0x000001e7] Attempt to access invalid address.
VirtualAlloc() failed: [0x00000008] Not enough memory resources are available to process this command.
VirtualFree() failed: [0x000001e7] Attempt to access invalid address.
PHP Fatal error: Out of memory (allocated 918552576) (tried to allocate 4096 bytes) in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
Fatal error: Out of memory (allocated 918552576) (tried to allocate 4096 bytes) in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52.
Hello Kreait
i have setup all the thing but i got error like
Kreait\Firebase\ServiceAccount\Discovery\FromEnvironmentVariable: The environment variable "FIREBASE_CREDENTIALS" is not set.\nKreait\Firebase\ServiceAccount\Discovery\FromEnvironmentVariable: The environment variable "GOOGLE_APPLICATION_CREDENTIALS" is not set.\nKreait\Firebase\ServiceAccount\Discovery\FromGoogleWellKnownFile: The well known file is not readable or invalid\ncURL error 6: Could not resolve host: metadata.google.internal; Unknown error (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)
can you please give me some solution.
With Laravel 8 being released shortly, it's probably time to update. Not sure about Lumen compatibility as it doesn't seem to have an 8.x branch yet. Lumen installer is confirmed as abandoned.
I think the documentation needs to be more clear to Laravel devs for using Facades instead of creating Kreait\Firebase\Factory
.
I've encountered a caching issue by following the documentation. What I've done is created a Kreait\Firebase\Factory
instance and create dynamic links.
Example:
(new \Kreait\Firebase\Factory())
->createDynamicLinksService($domain)
->createDynamicLink($url, $type);
It's working fine at my local since I don't cache my config at my local. But when I go live, this code doesn't work any more because the production runs php artisan config:cache
. The Factory tries to resolve credentials through FromEnvironmentVariable::getValueFromEnvironment()
. However the $_ENV
is empty since I cached. If I want to use the code above I must create a ServiceAccount
and attach it to the factory by withServiceAccount()
method, and turn off auto discovery.
By switching to facade and then it works, which makes sense because it's facade instance is using the cached config.
FirebaseDynamicLinks::createDynamicLink($url, $type);
This library is awesome. I think the documentation could be better to remind Laravel developers MUST/PREFER using Facade to auto-discovery the service provider.
I am using laravel 5.2.
I have nearly 15k users in my db. I used to send notification to each user based on their registered token. 1000 user at a time along with their token and the message It was taking so long.
Now I am trying to create a common topic for now, and I will subscribe every user to this topic.
I created a simple script to subscribe them all. I know I can't subscribe more than 1000 users at a time.
It's obvious there is many reasons that a user has not been subscribed. for example .
The token has expired.
Here is the code to subscribe all the users.
//Start subscribing all user to a common topic
//collect all users tokens
$results = User::select( 'regId')
->get()->toArray();
$user_tokens = array();
foreach($results as $result) {
array_push($user_tokens, $result['regId']);
}
//subscribe all users in batches
$batch_size = 1000; // 1000 per request
$iterations = ceil(count($user_tokens) / $batch_size); // determine how many iterations are needed
for ($i = 0; $i < $iterations; $i++) {
$offset = $i * $batch_size;
$batch_of_1000_user_ids = array_slice($user_tokens, $offset, $batch_size);
$messaging->subscribeToTopic('test', $batch_of_1000_user_ids);
}
//End sbuscribing all users to a common topic
So I want to know.
How can I know if a user is successfully subscribed?
Does this method $messaging->subscribeToTopic('test', $batch_of_1000_user_ids);
generate any error if a user hasn't been subscribed.
Also, does this process stops if a user hasn't been subscribed succsessfuly?
for example - suppose first nth user are subscribed, and there is an error on n+1rst user in that case what will happen . Will this method skip that user and continue subscribing rest users.
It will be easier for me to track how many users has not been subscribed.
I found some reference on the docs on Validate messages Section , but I am not sure if this will work in this case.
try {
$firebase->getMessaging()->validate($message);
} catch (InvalidMessage $e) {
print_r($e->errors());
}
Please, make compatible with guzzlehttp/guzzle ^7.0.1
to satisfy Laravel 8 requirements.
So far, it's the only incompatibility.
Thank you.
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
Unable to create a FirestoreClient: Class 'Google\Cloud\Firestore\FirestoreClient' not found
$database = app('firebase.firestore')->database();
$var_list = $database->collection('tokens')->document('tokens')->snapshot();
return [$var_list];
Dears,
Firstly, sorry for my bad english. I have a server in google cloud platform with ubuntu, in my local machine, the project works correctly, but when deploy in a server in google cloud, have this error:
"message": "Missing or insufficient permissions.",
"code": 7,
"status": "PERMISSION_DENIED",
"details": []
How to solve this?
I want to fetch docs from firestore. Can I use this?
Please, add Lumen compatibility.
[2020-01-07 03:24:04] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Argument 1 passed to Kreait\Laravel\Firebase\ServiceProvider::Kreait\Laravel\Firebase\{closure}() must be an instance of Illuminate\Contracts\Foundation\Application, instance of Laravel\Lumen\Application given, called in /home/vagrant/code/api/vendor/illuminate/container/Container.php on line 791 in /home/vagrant/code/api/vendor/kreait/laravel-firebase/src/ServiceProvider.php:83
Hello All,
I am facing one critical issue. I am trying to send notification to multiple tokens but one at time in loop. I am getting code=200 as response but actual notifications are not received by mobile user.(This is happening with some of token from that list)
I checked sending notification from console to those tokens and that is getting delivered. But not when sent via code.
Any suggestion how I can go about this issue?
Having really bad time with this as all notifications are not getting delivered
Hi, I'm trying to send a push notification to a device but cannot seem to make it work, added this package today and followed the docs but I must be missing something. Little help would be appreciated. This is what I have so far:
Hi, I'm trying to send a push notification to a device but cannot seem to make it work, added this package today and followed the docs but I must be missing something. Little help would be appreciated. This is what I have so far:
<?php
namespace App\Services;
use Exception;
use Kreait\Firebase;
use Kreait\Firebase\Factory;
use Kreait\Firebase\Database;
use Kreait\Firebase\ServiceAccount;
use Kreait\Firebase\Exception\Auth\EmailExists as FirebaseEmailExists;
class FirebaseService
{
/**
* @var Firebase
*/
protected $firebase;
public function __construct()
{
$serviceAccount = ServiceAccount::fromArray([
"type" => "service_account",
"project_id" => config('services.firebase.project_id'),
"private_key_id" => config('services.firebase.private_key_id'),
"private_key" => config('services.firebase.private_key'),
"client_email" => config('services.firebase.client_email'),
"client_id" => config('services.firebase.client_id'),
"auth_uri" => "https://accounts.google.com/o/oauth2/auth",
"token_uri" => "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url" => "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url" => config('services.firebase.client_x509_cert_url')
]);
$this->firebase = (new Factory)
->withServiceAccount($serviceAccount)
->create();
}
}
<?php
namespace App\Providers;
use App\Services\FirebaseService;
use Illuminate\Support\ServiceProvider;
use App\Observers\UserFavouriteObserver;
class FirebaseServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind('FirebaseService', function () {
return new FirebaseService();
});
}
}
<?php
namespace App\Helpers;
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Firebase\Messaging\Notification;
use Kreait\Firebase\Messaging;
class PushNotifications
{
public function send_push()
{
$deviceToken = 'token';
$notification = Notification::fromArray([
'title' => 'title test',
'body' => 'body test',
]);
$message = CloudMessage::withTarget('token', $deviceToken)
->withNotification($notification);
$messaging = app('firebase.messaging');
$messaging->send($message);
}
}
I can check valid user by verify password
$user = app('firebase.auth')->verifyPassword($email,$password);
if($user->emailVerified) {
echo 'login success';
}
Now further query
$docRef = app('firebase.firestore')->database()->collection('MyCollectionName')
->where('name', '==', 'anyname')
->documents();
But how the above query is authenticated to user logged in.
Hey there!
I was wondering whether you guys could help me with an issue I'm facing.
App.php:
$app->withFacades();
$app->register(Kreait\Laravel\Firebase\ServiceProvider::class);
DomainService.php
public static function insertMessage(String $customerId, Message $message)
{
$collectionDocument = app('firebase.firestore')
->database()
->collection(ChatService::$collectionName)
->document($customerId);
return $collectionDocument
->collection(ChatService::$subCollectionName)
->newDocument()
->create($message->jsonSerialize());
}
When I run this app on Google App Engine (Flex) or Google Cloud Run and invoke this method call via a Rest call, the average response time is around 16 seconds. When running locally, this is around 500ms.
Do you know where the increase in latency might come from?
We've also used https://github.com/firevel/firestore/tree/master/src, which doesn't have this problem, but Firevel is missing other functionalities.
Versions used:
"kreait/laravel-firebase": "^1.5",
"laravel/lumen-framework": "^6.0"
How to create Auth
Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined method
$factory = app('firebase.auth');
$auth = $factory->createAuth();
return [ $auth];
Hello, thank you for your great package.
i retrieve my token properly from flutter and i confirm it is correct by sending a test message on firebase console. I get it on my device properly.
What could be my error?
[2020-04-02 01:47:21] local.ERROR: The registration token is not a valid FCM registration token {"userId":1,"exception":"[object] (Kreait\Firebase\Exception\Messaging\InvalidMessage(code: 400): The registration token is not a valid FCM registration token at D:\WebServer\ZeinTekWebServices\liveroot\merlin-core\vendor\kreait\firebase-php\src\Firebase\Exception\Messaging\InvalidMessage.php:43)
[stacktrace]
Thank you
$deviceToken = 'cO_GzDW6jaE:APA91bEBnhoMPRWg6A_tGnGE-gJxgEsOoaZKjHSf4AlPRQozdfCWoJqxUOWnEn37rPUAZ49ZGDp0Sp-VuSME8mjdBkCFvhsCr-tIKyUL8Ro4u45AyhR4AwQZta_3vR_9DPOieTGekCJc';
$title = 'Package is being delivered';
$body = 'Your order 9847GH8474 is on it\'s way to you.';
$imageUrl = 'http://lorempixel.com/400/200/';
$notification = Notification::fromArray([
'title' => $title,
'body' => $body,
// 'image' => $imageUrl,
]);
$notification = Notification::create($title, $body);
$data = [
'click_action' => 'FLUTTER_NOTIFICATION_CLICK',
'action' => 'new_notification',
'notification_id' => '888888888',
'notification_uid' => '1111-2222-3333-4444',
'notification_foreignUID' => '5555-6666-7777-8888',
'notification_foreignUID_type' => 'user',
'notification_title' => $title,
'notification_message' => $body,
'notification_asset_type' => 'image',
'notification_image' => 'http://f48aa427.ngrok.io/storage/images_products/860a6ac4-bd66-4c3b-b07f-450f7cdcc007_2020-01-20_15-15-21_0001.jpg',
'notification_icon' => null,
'notification_account_type' => 'client',
'notification_read_status' => 0,
'notification_status' => 'active',
'notification_created_at' => '2020-03-29 02:09:00',
'notification_updated_at' => '2020-03-29 02:09:00',
];
$message = CloudMessage::withTarget('token', $deviceToken)
->withNotification($notification) // optional
->withData($data);// optional
$message = CloudMessage::fromArray([
'token' => $deviceToken,
'notification' => [/* Notification data as array */], // optional
'data' => [/* data array */], // optional
]);
$messaging = app('firebase.messaging');
$messaging->send($message);
Hi
please provide an example for using this extra lib
Hi,
Can you please provide any route/model binding and sync firebase/firestore data to laravel eloquent model?
Purpose is I can used all the Laravel functionality with the firebase/firestore and used it in development.
Please give response to this questions, is there any way we can go forward with this?
Thank You,
Vivek
Hi,
Anybody here having the issue:
Unable to locate publishable resources.
Publishing complete.
This showed up after I entered this one
php artisan vendor:publish --provider="Kreait\Laravel\Firebase\ServiceProvider" --tag=config
Prior to it, I entered this:
composer require kreait/laravel-firebase
I also tried this one below
<?php // config/app.php return [ // ... 'providers' => [ // ... Kreait\Laravel\Firebase\ServiceProvider::class ] // ... ];
but is getting this error instead after publishing the service.
**In ProviderRepository.php line 208:
Class 'Kreait\Laravel\Firebase\ServiceProvider' not found**
I tried to look for the solution in google but can't find someone having the same problem using Kreait.
I'm using PHPv 7.3 and Laravel v7.4.
Thanks in advance
I am using laravel 5.2 and the error is coming from below file.
vendor\kreait\laravel-firebase\src\ServiceProvider.php on line 55.
if ($cacheStore = $config['cache_store'] ?? null) {
$factory = $factory->withVerifierCache(
$app->make('cache')->store($cacheStore)// from here
);
}
How i can set noitifications sound i cont find it
try to make samples of Laravel calls none of this working
ymfony\Component\Debug\Exception\FatalThrowableError: Call to undefined method Kreait\Firebase\Messaging::createMessaging()
$messaging = app('firebase.messaging')->createMessaging();
$message = CloudMessage::withTarget('token', $id)
->withNotification(Notification::create('testing', 'working ok'))
->withData(['test' => 'value']);
$m = $messaging->send($message);
Who can help me with how to write testing for this package?
Thank you!
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.