Skip to content

Commit

Permalink
Merge pull request #29 from baggednismo/patch
Browse files Browse the repository at this point in the history
Added priority variable to set when sending a new notification
  • Loading branch information
sayaamirul authored Jun 25, 2019
2 parents abd6a13 + 2ae3f39 commit 027a54d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
25 changes: 17 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ A simple package that help you send a Firebase notification with your Laravel ap

You can pull the package via composer :

``` bash
```bash
$ composer require kawankoding/laravel-fcm
```

Next, You must register the service provider :
Next, You must register the service provider :

```php
```php
// config/app.php

'Providers' => [
// ...
Kawankoding\Fcm\FcmServiceProvider::class,
// ...
Kawankoding\Fcm\FcmServiceProvider::class,
]
```
```

If you want to make use of the facade you must install it as well :
If you want to make use of the facade you must install it as well :

```php
// config/app.php
Expand Down Expand Up @@ -54,6 +54,7 @@ return [
```

Set your FCM Server Key in `.env` file :

```
APP_NAME="Laravel"
# ...
Expand All @@ -63,20 +64,24 @@ FCM_SERVER_KEY=putYourKeyHere
### Usage

If You want to send a FCM with just notification parameter, this is an example of usage sending a FCM with only data parameter :

```php
fcm()
->to($recipients) // $recipients must an array
->priority('high')
->data([
'title' => 'Test FCM',
'body' => 'This is a test of FCM',
])
->send();
```

If You want to send a FCM to topic, use method toTopic($topic) instead to() :
If You want to send a FCM to topic, use method toTopic(\$topic) instead to() :

```php
fcm()
->toTopic($topic) // $topic must an string (topic name)
->priority('normal')
->notification([
'title' => 'Test FCM',
'body' => 'This is a test of FCM',
Expand All @@ -85,9 +90,11 @@ fcm()
```

If You want to send a FCM with just notification parameter, this is an example of usage sending a FCM with only notification parameter :

```php
fcm()
->to($recipients) // $recipients must an array
->priority('high')
->notification([
'title' => 'Test FCM',
'body' => 'This is a test of FCM',
Expand All @@ -96,9 +103,11 @@ fcm()
```

If You want to send a FCM with both data & notification parameter, this is an example of usage sending a FCM with both data & notification parameter :

```php
fcm()
->to($recipients) // $recipients must an array
->priority('normal')
->data([
'title' => 'Test FCM',
'body' => 'This is a test of FCM',
Expand Down
10 changes: 9 additions & 1 deletion src/Fcm.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Fcm
protected $data;
protected $notification;
protected $timeToLive;
protected $priority;

public function to(array $recipients)
{
Expand Down Expand Up @@ -42,6 +43,13 @@ public function notification(array $notification = [])
return $this;
}

public function priority(string $priority)
{
$this->priority = $priority;

return $this;
}

public function timeToLive(int $timeToLive)
{
if ($timeToLive < 0) {
Expand All @@ -62,7 +70,7 @@ public function send()

$payloads = [
'content_available' => true,
'priority' => 'high',
'priority' => $this->priority,
'data' => $this->data,
'notification' => $this->notification
];
Expand Down

0 comments on commit 027a54d

Please sign in to comment.