GithubHelp home page GithubHelp logo

blue-cookie / laravel-firebase Goto Github PK

View Code? Open in Web Editor NEW

This project forked from multicaret/laravel-firebase

0.0 1.0 0.0 11 KB

Laravel FCM (Firebase Cloud Messaging) Notification Channel

License: MIT License

PHP 100.00%

laravel-firebase's Introduction

laravel-firebase

This package makes it easy to send notifications using Firebase Cloud Messaging (FCM) with Laravel Notification Channel.

Installation

This package can be installed through Composer.

composer require liliom/laravel-firebase

If you don't use Laravel 5.5+ you have to add the service provider manually

// config/app.php
'providers' => [
    ...
    Liliom\Firebase\FirebaseServiceProvider::class,
    ...
];

Now add you Firebase API Key in config/services.php.

return [
	....
    'firebase' => [
        'key' => ''
    ],
    ....
];

Usage

Les's create a notification using artisan commend:

php artisan make:notification FirebaseNotification

Now you can use firebase channel in your vie() mothod.

public function via($notifiable)
{
    return ['firebase'];
}

Add a pubilc method toFirebase($notifiable) to your notification class, and return an instance of FirebaseMessage:

public function toFirebase($notifiable)
{
    return (new \Liliom\Firebase\FirebaseMessage)
        ->notification([
            'title' => 'Notification title',
            'body' => 'Notification body',
            'sound' => '', // Optional
	    'icon' => '', // Optional
	    'click_action' => '' // Optional
        ])
        ->setData([
	    'param' => 'zxy' // Optional
	])
	->setPriority('high'); // Default is 'normal'
}

Available methods:

  • setData: To Set data.
  • setPriority: To Set priority.
  • setTimeToLive: To Set time_to_live.
  • setCollapseKey: To Set collapse_key.
  • setNotification: To Set notification.
  • setCondition: To Set condition.
  • setContentAvailable: To Set content_available.
  • setMutableContent: To Set mutable_content.
  • setPackageName: To Set restricted_package_name.

When sending to specific device(s), make sure your notifiable entity has routeNotificationForFirebase method defined:

Note: You can send to many devices by return an array of tokens.

/**
 * Route notifications for Firebase channel.
 *
 * @return string|array
 */
public function routeNotificationForFirebase()
{
    return $this->device_tokens;
}

License

The MIT License (MIT). Please see License File for more information.

laravel-firebase's People

Contributors

adamanderson86 avatar evertt avatar hussam3bd avatar mkwsra avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.