Skip to content

Commit cd6fb1e

Browse files
authored
Create README.md
1 parent 7257624 commit cd6fb1e

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# laravel-firebase
2+
Google Firebase Notification for Laravel 5.2
3+
4+
This package makes it easy to send Firebase Notification with Laravel 5.2.
5+
6+
## Installation
7+
8+
You can install the package via composer:
9+
10+
``` bash
11+
composer require alfa6661/laravel-firebase
12+
```
13+
14+
You must install the service provider:
15+
16+
```php
17+
// config/app.php
18+
'providers' => [
19+
...
20+
Alfa6661\Firebase\FirebaseServiceProvider::class,
21+
],
22+
```
23+
24+
### Setting up your Firebase account
25+
26+
Add your Firebase Key to your `config/services.php`:
27+
28+
```php
29+
// config/services.php
30+
...
31+
'firebase' => [
32+
'api_key' => env('FIREBASE_API_KEY'),
33+
],
34+
...
35+
```
36+
37+
38+
## Usage
39+
40+
Now you can use the channel in your `via()` method inside the notification:
41+
42+
``` php
43+
use Alfa6661\Firebase\FirebaseChannel;
44+
use Alfa6661\Firebase\FirebaseMessage;
45+
use Illuminate\Notifications\Notification;
46+
47+
class CreditWasCreated extends Notification
48+
{
49+
public function via($notifiable)
50+
{
51+
return [FirebaseChannel::class];
52+
}
53+
54+
public function toFirebase($notifiable)
55+
{
56+
return FirebaseMessage::create()
57+
->title('Title')
58+
->body('Push notification body')
59+
->data(['id' => $notifiable->id]);
60+
}
61+
}
62+
```
63+
64+
In order to let your Notification know which device user(s) you are targeting, add the `routeNotificationForFirebase` method to your Notifiable model.
65+
66+
You can either return a single device token, or if you want to notify multiple device just return an array containing all devices.
67+
68+
```php
69+
public function routeNotificationForFirebase()
70+
{
71+
return ["DEVICE_TOKEN", "DEVICE_TOKEN"];
72+
}
73+
```

0 commit comments

Comments
 (0)