https://github.com/grohiro/laravel-firebase
Firebase Cloud Message for Laravel
https://github.com/grohiro/laravel-firebase
Last synced: 26 days ago
JSON representation
Firebase Cloud Message for Laravel
- Host: GitHub
- URL: https://github.com/grohiro/laravel-firebase
- Owner: grohiro
- Created: 2017-12-18T08:27:49.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-14T11:35:24.000Z (over 8 years ago)
- Last Synced: 2025-12-01T00:22:08.925Z (6 months ago)
- Language: PHP
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# laravel-firebase
Firebase Channel plugin for Laravel.
```php
use Illuminate\Notifications\Notification;
use Grohiro\Laravel\FCM\FirebaseChannel;
use paragraph1\phpFCM\Message;
use paragraph1\phpFCM\Recipient\Device;
use paragraph1\phpFCM\Notification;
/**
* @see https://laravel.com/docs/5.5/notifications#custom-channels
*/
class PushMessage extends Notification
{
public function via($notifiable)
{
return [FirebaseChannel::class];
}
public function toFcmMessage($user)
{
// @see https://github.com/Paragraph1/php-fcm
$note = new Notification('test title', 'testing body');
$note->setIcon('notification_icon_resource_name')
->setColor('#ffffff')
->setBadge(1);
$message = new Message();
$message->addRecipient(new Device($user->user_device_token));
$message->setNotification($note)
->setData(array('someId' => 111));
return $message;
}
}
```
## Requirements
- Laravel 5.5+
- [paragraph1/php-fcm](https://github.com/Paragraph1/php-fcm)
## Usage
### 1. Install laravel-firebase
```bash
$ composer require grohiro/laravel-firebase dev-master
```
### 2. Setup Guzzle HTTP client
Add the ServiceProvider to `app.php`
```php
// config/app.php
'providers' => [
\Grohiro\Laravel\FCM\ServiceProvider::class,
];
```
### 3. Create Laravel Notification class
```
php artisan make:notification PushNotification
```
### 4. Set Firebase API key
```php
// config/app.php
'firebase' => [
'api_key' => 'your-api-key'
],
```