Skip to content

Commit 0166fb5

Browse files
committed
add README and LICENSE
1 parent 35bb32e commit 0166fb5

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The MIT License (MIT)
2+
3+
Copyright (c) Liliom
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# laravel-firebase
2+
This package makes it easy to send notifications using Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/) (FCM) with Laravel Notification Channel.
3+
4+
## Installation
5+
6+
This package can be installed through Composer.
7+
8+
``` bash
9+
composer require liliom/laravel-firebase
10+
```
11+
12+
If you don't use Laravel 5.5+ you have to add the service provider manually
13+
14+
```php
15+
// config/app.php
16+
'providers' => [
17+
...
18+
Liliom\Firebase\FirebaseServiceProvider::class,
19+
...
20+
];
21+
```
22+
23+
Now add you Firebase API Key in `config/services.php`.
24+
25+
```php
26+
return [
27+
....
28+
'firebase' => [
29+
'key' => ''
30+
],
31+
....
32+
];
33+
```
34+
35+
## Usage
36+
37+
Les's create a notification using artisan commend:
38+
39+
```bash
40+
php artisan make:notification FirebaseNotification
41+
```
42+
43+
Now you can use `firebase` channel in your `vie()` mothod.
44+
45+
```php
46+
public function via($notifiable)
47+
{
48+
return ['firebase'];
49+
}
50+
```
51+
52+
Add a pubilc method `toFirebase($notifiable)` to your notification class, and return an instance of `FirebaseMessage`:
53+
54+
```php
55+
public function toFirebase($notifiable)
56+
{
57+
return (new \Liliom\Firebase\FirebaseMessage)
58+
->notification([
59+
'title' => 'Notification title',
60+
'body' => 'Notification body',
61+
'sound' => '', // Optional
62+
'icon' => '', // Optional
63+
'click_action' => '' // Optional
64+
])
65+
->setData([
66+
'param' => 'zxy' // Optional
67+
])
68+
->setPriority('high'); // Default is 'normal'
69+
}
70+
```
71+
72+
## Available methods:
73+
74+
- `getData`: To Set `data`.
75+
- `getPriority`: To Set `priority`.
76+
- `getTimeToLive`: To Set `time_to_live`.
77+
- `getCollapseKey`: To Set `collapse_key`.
78+
- `getNotification`: To Set `notification`.
79+
- `getCondition`: To Set `condition`.
80+
- `getContentAvailable`: To Set `content_available`.
81+
- `getMutableContent`: To Set `mutable_content`.
82+
- `getPackageName`: To Set `restricted_package_name`.
83+
84+
When sending to specific device(s), make sure your notifiable entity has `routeNotificationForFirebase` method defined:
85+
> **Note:** You can send fo many devices by return an array of tokens.
86+
87+
```php
88+
/**
89+
* Route notifications for Firebase channel.
90+
*
91+
* @return string|array
92+
*/
93+
public function routeNotificationForFirebase()
94+
{
95+
return $this->device_tokens;
96+
}
97+
```
98+
99+
## License
100+
101+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

0 commit comments

Comments
 (0)