Package Data | |
---|---|
Maintainer Username: | douglasresendemaciel |
Maintainer Contact: | eu@douglasresende.com (Douglas Resende Maciel) |
Package Create Date: | 2016-11-03 |
Package Last Update: | 2017-11-14 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-02-07 03:00:06 |
Package Statistics | |
---|---|
Total Downloads: | 8,810 |
Monthly Downloads: | 35 |
Daily Downloads: | 1 |
Total Stars: | 11 |
Total Watchers: | 3 |
Total Forks: | 6 |
Total Open Issues: | 1 |
# Firebase Cloud Messaging library for laravel´s notifications
This library allow send push notifications to Firebase Cloud Messaging through laravel´s notifications.
It´s possible send notifications to websites, Android and IOS without any other integration.
Run the following command from you terminal:
composer require "douglasresendemaciel/fcm-laravel-notification:@dev"
or add this to require section in your composer.json file:
"douglasresendemaciel/fcm-laravel-notification"
then run composer update
Once it is installed, you need to register the service provider. Open up config/app.php and add the following to the providers key.
'providers' => [
...
DouglasResende\FCM\NotificationServiceProvider::class
...
First, create your notification class using artisan php artisan make:notification MyNotification
Implement your notification:
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use DouglasResende\FCM\Messages\FirebaseMessage;
class MyNotification extends Notification
{
use Queueable;
public function via($notifiable)
{
return ['fcm'];
}
public function toFcm($notifiable)
{
return (new FirebaseMessage())->setContent('Test Notification', 'This is a Test');
}
}
Implement on your notifiable
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
class User extends Model {
use Notifiable;
public function routeNotificationForFcm() {
//return a device token, either from the model or from some other place.
return $this->device_token;
}
}
Open up config/broadcasting.php and add the Firebase api key to the connections section:
...
'fcm' => [
'key' => env('FCM_API_KEY','YOUR_API_KEY')
]
...
Trigger notification:
$User = User::find(1);
//Send Notification
$User->notify(new MyNotification());
For more information read the official documentation at https://laravel.com/docs/5.3/notifications