{"id":17437143,"url":"https://github.com/mrgarest/laravel-firebase-sender","last_synced_at":"2025-12-29T12:40:03.692Z","repository":{"id":257801545,"uuid":"863476948","full_name":"mrgarest/laravel-firebase-sender","owner":"mrgarest","description":"Laravel library for sending notifications with Firebase Cloud Messaging (FCM)","archived":false,"fork":false,"pushed_at":"2025-07-26T18:57:46.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-30T11:46:44.882Z","etag":null,"topics":["fcm","fcm-notifications","firebase","laravel","laravel-package","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrgarest.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-09-26T11:11:26.000Z","updated_at":"2025-07-26T18:57:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"fc37b025-01de-447d-8c07-b1a0f41c3d20","html_url":"https://github.com/mrgarest/laravel-firebase-sender","commit_stats":null,"previous_names":["mrgarest/laravel-firebase-sender"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/mrgarest/laravel-firebase-sender","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrgarest%2Flaravel-firebase-sender","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrgarest%2Flaravel-firebase-sender/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrgarest%2Flaravel-firebase-sender/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrgarest%2Flaravel-firebase-sender/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrgarest","download_url":"https://codeload.github.com/mrgarest/laravel-firebase-sender/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrgarest%2Flaravel-firebase-sender/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274935983,"owners_count":25376836,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-13T02:00:10.085Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fcm","fcm-notifications","firebase","laravel","laravel-package","php"],"created_at":"2024-10-17T11:06:04.916Z","updated_at":"2025-12-24T12:47:56.052Z","avatar_url":"https://github.com/mrgarest.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Firebase Sender\n\nLaravel library for sending notifications with Firebase Cloud Messaging (FCM).\n\n_If you have previously used the old version of v2, you should read the instructions for [migrating to v3](https://github.com/mrgarest/laravel-firebase-sender/blob/master/migrating-to-v3.md)._\n\n### Supported platforms\n\n| ✅  | Platform  |\n| --- | -------- |\n| ✅  | Apns     |\n| ✅  | Android  |\n| ✅  | WebPush  |\n\n## Installation\n\nYou can install the package via composer:\n\n```\ncomposer require mrgarest/laravel-firebase-sender\n```\n\n## Configuration\n\nAfter installing the package, you will need to publish the configuration file `firebase-sender.php`\n\n```\nphp artisan vendor:publish --tag=firebase-sender-config\n```\n\nAfter publishing the configuration file, you need to open it and add the Service account data from the Firebase console.\n\n_If you don't know how to get a Service account, here is a [video from YouTube](https://www.youtube.com/watch?v=aeBiLIw2KnY)._\n\n## Usage\n\n`FirebaseSender` is a class that is responsible for sending notification to devices via Firebase Cloud Messaging (FCM) using a service account with Firebase.\n\n```php\n$firebaseSender = new FirebaseSender('MY_SERVICE_ACCOUNT_NAME');\n```\n\n`MY_SERVICE_ACCOUNT_NAME` - the identifier of your service account registered in the `firebase-sender.php` configuration.\n\n### Send a notification to a specific device\n\nTo send a notification directly to the device, use the `setDeviceToken` method, passing in a unique device token generated by Firebase.\n\n```php\n$firebaseSender-\u003esetDeviceToken('DEVICE_TOKEN');\n```\n\n_Note that you can use either `setDeviceToken` or `setTopic`. You cannot use both methods._\n\n### Send a notification on a specific topic\n\nTo send a notification to all devices subscribed to a specific topic, use the setTopic() method, passing the topic name as a string:\n\n```php\n$firebaseSender-\u003esetTopic('TOPIC_NAME');\n```\n\n#### Topic conditions\n\nThe TopicCondition class allows you to create complex logical conditions for determining the topics to which a notification will be sent.\n\nTo send a notification to a combination of topics, you need to build a boolean expression that describes the target topics. The expression can contain the AND (`\u0026\u0026`) and OR (`||`) operators, as well as grouping using parentheses.\n\nFor example, to send a notification to devices subscribed to `topicA` and (`topicB` or `topicC`), you can build the following expression:\n\n```php\n$firebaseSender-\u003esetTopic(TopicCondition::make()\n    -\u003etopic('topicA')\n    -\u003eand()\n    -\u003egroup(fn($group) =\u003e $group-\u003etopic('topicB')-\u003eor()-\u003etopic('topicC'))\n);\n```\n\n### Set notifications\n\nThe `setNotification` method allows you to set the main content of the notification that will be sent through Firebase.\n\n```php\n$firebaseSender-\u003esetNotification(new NotificationPush(\n    title: 'TITLE',\n    body: 'BODY'\n));\n```\n\n### Set notifications for Android\n\nThe `setAndroid` method allows you to set the notification content for Android devices.\n\n```php\n$firebaseSender-\u003esetAndroid(new AndroidPush(\n    title: 'TITLE',\n    body: 'BODY'\n));\n```\n\n### Set notifications for APNs\n\nThe `setApns` method allows you to set the notification content for APNs (Apple Push Notification Service).\n\n```php\n$firebaseSender-\u003esetApns(new ApnsPush(\n    title: 'TITLE',\n    body: 'BODY'\n));\n```\n\n### Send a notification\n\nAfter configuring the notification, you can send it by calling the `send` method.\n\n```php\n$firebaseSender-\u003esend(): SendReport\n```\n\nIf you don't want to send the message immediately, but want to schedule it for later, you can use the `sendJob` method. To use this method, [queues](https://laravel.com/docs/12.x/queues) must be configured in your Laravel project.\n\n```php\n$firebaseSender-\u003esendJob(Carbon $scheduledAt, int $chunkLength = 10, int $maxRand = 0): void\n```\n\nThis method takes one required value and two optional values.\n\n| Value          | Type     | Required | Description                                                    |\n| -------------- | -------- | -------- | -------------------------------------------------------------- |\n| `$scheduledAt` | `Carbon` | Yes      | Date when notification should be sent                          |\n| `$chunkLength` | `int`    | No       | Allows you to split messages into chunks                       |\n| `$maxRand`     | `int`    | No       | Adds a random number of seconds to the chunk dispatch schedule |\n\n### Clear\n\nWhen you need to send new notifications, you can simply clear the previously sent data without having to re-announce the class.\n\n```php\n$firebaseSender-\u003eclear(): void\n```\n\n### Grouping\n\nUsing the `setGroup` grouping method, you can send multiple messages at once by combining messages into groups.\n\n```php\n$firebaseSender-\u003esetGroup(int $index): void\n```\n\nEach group must have its own index, recipient, and message body.\n\nExample of sending group notifications:\n```php\n$firebaseSender = new FirebaseSender('MY_SERVICE_ACCOUNT_NAME');\n\n$firebaseSender-\u003esetGroup(0);\n$firebaseSender-\u003esetDeviceToken(\"MY_DEVICE_TOKEN_1\");\n$firebaseSender-\u003esetNotification(new NotificationPush(\n    title: \"Lorem ipsum\",\n    body: 'Lorem ipsum dolor sit amet consectetur adipisicing elit.',\n));\n\n$firebaseSender-\u003esetGroup(1);\n$firebaseSender-\u003esetDeviceToken(\"MY_DEVICE_TOKEN_2\");\n$firebaseSender-\u003esetNotification(new NotificationPush(\n    title: \"Lorem ipsum\",\n    body: 'Lorem ipsum dolor sit amet consectetur adipisicing elit.',\n));\n\n$firebaseSender-\u003esend();\n```\n\n### Custom messages\n\nWith this method, you can specify a custom data structure for the messages to be sent through FCM. This can be useful for sending additional information that is not included in the standard notification options.\n\n```php\n$firebaseSender-\u003esetMessages([\n    [\n        'token' =\u003e 'DEVICE_TOKEN',\n        'notification' =\u003e [\n            'title' =\u003e 'TITLE',\n            'body' =\u003e 'BODY'\n        ]\n    ]\n]);\n```\n\n_When using `setMessages`, the `setNotification`, `setAndroid` and `setApns` methods will not work._\n\n\n## Localized notifications\n\n`AndroidPush` and `ApnsPush` support sending localized notifications, which allows you to dynamically display text depending on the user's language.\n\nTo do this, use the `titleLocKey` and `bodyLocKey` parameters, which specify the keys to localized strings in your application's resources.\n\nYou can also specify the `titleLocArgs` and `bodyLocArgs` parameters, which can be used to pass values that will be inserted into localized notification templates.\n\n## Notification log\n\nIf you want to use the log of sent notifications, you will also need to publish the migration file and perform the migration.\n\n```\nphp artisan vendor:publish --tag=firebase-sender-migrations\n```\n\n```\nphp artisan make:migration\n```\n\nTo store information about sent notifications in the database, you can enable the event log.\n\n```php\n$firebaseSender-\u003elogEnabled(bool $enabled = true): void\n```\n\nThe event log also supports two additional methods for adding payloads to the log.\n\n\n```php\n$firebaseSender-\u003esetPayload1(?string $payload = null): void\n$firebaseSender-\u003esetPayload2(?string $payload = null): void\n```\n\n### FirebaseSenderLog Query Scopes\n\n#### messageId\n\nFilter logs by the message ID.\n\n```php\n$query-\u003emessageId(45543643);\n```\n\n#### serviceAccount\n\nFilter logs by the service account used to send the notification.\n\n```php\n$query-\u003eserviceAccount('MY_SERVICE_ACCOUNT_NAME');\n```\n\n#### deviceToken\n\nFilter logs by the device token (for notifications sent to a specific device).\n\n```php\n$query-\u003edeviceToken('DEVICE_TOKEN');\n```\n\n#### Topic\n\nFilters records where the topic exactly matches the value passed.\n\n```php\n$query-\u003etopic('TOPIC_NAME');\n```\n\nIf you need to search for a topic that may appear as part of a condition, use the `matchTopic` method. It allows matching both exact topics and topics used in conditions.\n\n```php\n$query-\u003ematchTopic('TOPIC_NAME');\n```\n\nBy default, `matchTopic` checks for both exact and conditional matches. If you want to search only within conditions, pass true as the second argument:\n\n```php\n$query-\u003ematchTopic(\n    'TOPIC_NAME',\n    true\n);\n```\n\n#### Payload\n\n`payload1` and `payload2` filter logs by the first value of the user payload.\n\n```php\n$query-\u003epayload1('language');\n```\n\n#### createdBetween\n\nFilter logs created between two dates.\n\n```php\n$query-\u003ecreatedBetween(\n    Carbon::now(),\n    Carbon::now()-\u003esubHours(1)\n);\n```\n\n#### sentBetween\n\nFilter logs where the notification was sent between two dates.\n\n```php\n$query-\u003esentBetween(\n    Carbon::now(),\n    Carbon::now()-\u003esubHours(1)\n);\n```\n\n#### scheduledBetween\n\nFilter logs where the notification was scheduled between two dates.\n\n```php\n$query-\u003escheduledBetween(\n    Carbon::now(),\n    Carbon::now()-\u003esubHours(1)\n);\n```\n\n#### failedBetween\n\nFilter logs where the notification failed between two dates.\n\n```php\n$query-\u003efailedBetween(\n    Carbon::now(),\n    Carbon::now()-\u003esubHours(1)\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrgarest%2Flaravel-firebase-sender","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrgarest%2Flaravel-firebase-sender","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrgarest%2Flaravel-firebase-sender/lists"}