Skip to content

Commit

Permalink
v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
agordn52 committed Jun 8, 2024
1 parent 84d49a3 commit 82cc8f6
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 21 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [1.0.2] - 2024-06-08

* Update readme file
* Fix FcmMessage class
* Add postman collection example

## [1.0.1] - 2024-06-07

* Update web.php file
Expand Down
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ Manage FCM notifications with ease using Laravel FCM Channel.

- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
- [Usage](#usage)
- [Changelog](#changelog)
- [Testing](#testing)
- [Security](#security)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

This package has been built to make sending FCM messages easier.

There is also a Flutter [package](https://pub.dev/packages/laravel_fcm) you can use to save time for mobile development.
There is also a Flutter [package](https://pub.dev/packages/laravel_notify_fcm) you can use to save time for mobile development.

**Overview:**
* Add multiple (FCM) devices to a model in Laravel
Expand Down Expand Up @@ -49,7 +48,7 @@ ServiceProvider to your app.php: `App\Providers\FcmAppServiceProvider::class`

Then, ask if you want to run the migrations.

Here's the tables it will migrate:
Here are the tables it will migrate:
* fcm_devices

Add your Google Service Account to `firebase_service_account_json`.
Expand Down Expand Up @@ -110,7 +109,7 @@ The middleware is used when authenticating the user through the API endpoints th

This package adds API endpoints to your router to allow your application to store devices.

Postman collection [example](laravel_fcm_postman_collection.json)
Postman collection [example](laravel_fcm_channel.postman_collection.json)

---

Expand All @@ -127,7 +126,7 @@ Add this header key: `X-DMeta`
Value:
```
{
"uuid": "12992", // required, a uuid which should be from the device. The value must be persistented on the device.
"uuid": "12992", // required, a uuid which should be from the device.
"model": "iPhone", // optional
"version":" 12", // optional
"display_name": "Tim's iPhone", // optional
Expand All @@ -138,15 +137,17 @@ Value:
Payload body:
```
{
"is_active": 1, // optional, use this key to define if a device active or not
"is_active": 1, // optional, use this key to define if a device is active or not
"fcm_token": "kjnsdmnsdc0sdco23" // optional, when you have an FCM token for the device, use this key in the payload
}
```

This will add a new FCM device for a User.
If you provide a `fcm_token` in the payload then the user will be able to receive push notifications.

## Sending Notifications
## Usage

### Sending Notifications

To send a notification using the FCMChannel, first create a Notification in your Laravel project.
```bash
Expand Down Expand Up @@ -238,7 +239,7 @@ class User {
## Notification Object

Here's the attributes you can assign to a `FcmMessage`.
Here are the attributes you can assign to a `FcmMessage`.

```php
$notification = new FcmMessage();
Expand Down Expand Up @@ -284,15 +285,15 @@ $fcmDevice->sendFcmMessage([

Need to send notifications to a Flutter application?

Check out the offical repository for that project [here](https://github.com/nylo-core/laravel-notify-fcm).
Check out the official repository for that project [here](https://github.com/nylo-core/laravel-notify-fcm).

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
Please see [CHANGELOG](CHANGELOG.md) for recent changes.

## Security

If you discover any security related issues, please email hello@Nylo.com instead of using the issue tracker.
If you discover any security-related issues, please email hello@Nylo.com instead of using the issue tracker.

## Contributing

Expand All @@ -305,4 +306,4 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
The MIT License (MIT). Please view our [License File](LICENSE.md) for more information.
10 changes: 4 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@
],
"require": {
"php": ">=7.2",
"guzzlehttp/guzzle": "*",
"illuminate/support": "~5.8.0|6.x|7.x|8.x|9.x|10.x|11.x",
"kreait/firebase-php": "^7.11",
"nesbot/carbon": "^1.21|^2.0"
"kreait/firebase-php": "^7.12"
},
"require-dev": {
"orchestra/testbench": "~3.8.0|^4.0",
"phpunit/phpunit": "^8.0",
"php": ">=7.2",
"illuminate/support": "~5.8.0|6.x|7.x|8.x|9.x|10.x|11.x",
"nesbot/carbon": "^1.21|^2.0"
"illuminate/support": "~5.8.0|6.x|7.x|8.x|9.x|10.x|11.x"
},
"autoload": {
"psr-4": {
Expand All @@ -64,5 +61,6 @@
"LaravelFCM": "Nylo\\LaravelFCM\\LaravelFCM"
}
}
}
},
"minimum-stability": "stable"
}
90 changes: 90 additions & 0 deletions laravel_fcm_channel.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"info": {
"_postman_id": "08ee8406-6e12-407f-be94-ec79b444fe3c",
"name": "Laravel FCM Package",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "10721889"
},
"item": [
{
"name": "Update Devices",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{SANCTUM_TOKEN}}",
"type": "string"
}
]
},
"method": "PUT",
"header": [
{
"key": "X-DMeta",
"value": "{\"model\":\"iphone\",\"version\":\" 12\",\"uuid\":\"12992\",\"display_name\":\"iPhone\",\"platform\":\"IOS\"}"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"is_active\": 1,\n \"fcm_token\": \"fcm token\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{BASE_URL}}/api/fcm/device",
"host": [
"{{BASE_URL}}"
],
"path": [
"api",
"fcm",
"device"
]
}
},
"response": []
}
],
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{FCMUserToken}}",
"type": "string"
}
]
},
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "BASE_URL",
"value": "http://yourdomain.com",
"type": "string"
}
]
}
5 changes: 5 additions & 0 deletions src/Models/FcmDevice.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
use Illuminate\Database\Eloquent\Model;
use Nylo\LaravelFCM\Jobs\FcmSendNotificationJob;

/**
* Class FcmDevice
*
* @package Nylo\LaravelFCM\Models
*/
class FcmDevice extends Model
{

Expand Down
13 changes: 11 additions & 2 deletions src/Models/FcmMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace Nylo\LaravelFCM\Models;

/**
* Class FcmMessage
*
* @package Nylo\LaravelFCM\Models
*/
class FcmMessage {

private $title;
Expand Down Expand Up @@ -44,15 +49,19 @@ static function createFromArray($message)
}

if (isset($message['priority'])) {
$fcmMessage->priority($message['priority']);
if ($message['priority'] == 'highest') {
$fcmMessage->priorityHighest();
} else if ($message['priority'] == 'lowest') {
$fcmMessage->priorityLowest();
}
}

if (isset($message['data'])) {
$fcmMessage->data($message['data']);
}

if (isset($message['withoutDefaultSound'])) {
$fcmMessage->withoutDefaultSound($message['withoutDefaultSound']);
$fcmMessage->withoutDefaultSound();
}

return $fcmMessage;
Expand Down

0 comments on commit 82cc8f6

Please sign in to comment.