Coder Social home page Coder Social logo

ricardofontanelli / laravel-fanout-provider Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 6 KB

A simple and lightweight Laravel 4.2 and Laravel 5.* wrapper to interact with Fanout Service (fanout.io). Fanout is a SAAS that makes easy to build apps and APIs with realtime updates.

License: MIT License

PHP 100.00%
fanout fanout-service laravel service provider realtime-updates composer realm

laravel-fanout-provider's Introduction

Laravel Fanout

A simple and lightweight Laravel 4.2 and Laravel 5.* wrapper to interact with Fanout Service (fanout.io). Fanout is a SAAS that makes easy to build apps and APIs with realtime updates.

Get Started:

  • First of all, you should create an account on Fanout website (fanout.io)[https://fanout.io] to obtain the service credentials (Realm ID and Realm Key);
  • Install the lib via composer;
  • Update the config file and be happy!

Installation

The Laravel Fanout Service Provider can be installed via ...

composer require ricardofontanelli/laravel-fanout-provider:1.0 

or Composer by requiring the ricardofontanelli/laravel-fanout-provider package in your project's composer.json

{
    "require": {
        "ricardofontanelli/laravel-fanout-provider": "1.0"
    }
}

Then run a composer update

php composer update

To use the Laravel Fanout Service Provider, you must register the provider when bootstrapping your application.

In Laravel find the providers key in your config/app.php and register the Laravel Fanout Service Provider.

    // Laravel 4
    'providers' => array(
        // ...
        'RicardoFontanelli\LaravelFanout\FanoutServiceProvider',
    )

    // Laravel 5.*
    'providers' => [
        // ...
        RicardoFontanelli\LaravelFanout\FanoutServiceProvider::class,
    ]

Find the aliases key in your config/app.php and add the Laravel Fanout facade alias.

    // Laravel 4.*
    'aliases' => array(
        // ...
        'Fanout' => 'RicardoFontanelli\LaravelFanout\FanoutFacade',
    )

    // Laravel 5.*
    'aliases' => [
        // ...
        'Fanout' => RicardoFontanelli\LaravelFanout\FanoutFacade::class,
    ]

Publishing the package

Now, you should publish the package to generate the config file, after that, edit the config file with your Fanout credentials.

Laravel 4.2

The config file will be generate here: app/config/packages/ricardofontanelli/laravel-fanout-provider/config.php

php artisan config:publish ricardofontanelli/laravel-fanout-provider

Laravel 5.*

The config file will be generate here: app/config/fanout.php

php artisan vendor:publish --provider="RicardoFontanelli\LaravelFanout\FanoutServiceProvider"

Send a notification:

You have two options to test the front-end, the first is using the fanout Push Test Page, on Control Panel click the button "Push Test Page, on terminal open php artisan tinker and run:

// Send a notification
Fanout::publish('test', 'My first realtime message using Fanout.io!!');

The second one is creating a file called fanout.html like that, pay attention to change the information about your realm id:

<!DOCTYPE html>
<html>
    <head>
        <title>My Awesome Fanout + Laravel Example</title>
        <script src="http://{YOUR-REALM-ID}.fanoutcdn.com/bayeux/static/faye-browser-min.js"></script>
    </head>
    <body>
        <h2>My Awesome Fanout + Laravel Example</h2>
        <script>
            var client = new Faye.Client('http://{YOUR-REALM-ID}.fanoutcdn.com/bayeux');
                client.subscribe('my-channel', function (data) {
                alert('Got data: ' + data);
            });
        </script>
    </body>
</html>

Now, open the file fanout.html send your first message usign php artisan tinker and run:

// Send a notification
Fanout::publish('my-channel', 'My first realtime message using Fanout.io!!');

You are free to change the channel name, fanout doesn't force you to create theses channels before send messages.

Find more:

This is a simples service provider to help you to quickly implements Fanout in your app, you can find more details about the Fanout PHP sdk on [https://github.com/fanout/php-fanout]. Have a look at Fanout (Docs)[https://fanout.io/docs/] to see how to implement the service in your frontend;

laravel-fanout-provider's People

Contributors

ricardofontanelli avatar

Stargazers

 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.