Code Monkey home page Code Monkey logo

bridge's Introduction

Bridge Build Status Latest Stable Version License

Ever found yourself needing to access back end data in your JavaScript or front end code? Well that's the aim of this package.

Installation

This package requires PHP 5.4+, and includes a Laravel 5 Service Provider and Facade.

We recommend installing the package through composer. You can either call composer require coreplex/notifier in your command line, or add the following to your composer.json and then run either composer install or composer update to download the package.

"coreplex/bridge": "~0.1"

Laravel 5 Integration

To use the package with Laravel 5 firstly add the javascript service provider to the list of service providers in app/config/app.php.

'providers' => array(

  Coreplex\Bridge\JavascriptServiceProvider::class,

);

If you wish to use the facade then add the following to your aliases array in app/config/app.php.

'aliases' => array(

  'Javascript'  => Coreplex\Bridge\Facades\Javascript::class,

);

Usage

To get started with the JavaScript component you simply need to create a new instance of the Javascript class.

$bridge = new Javascript();

Or if you are using laravel then you can access the class via it's facade or you can resolve it from the IOC container by its contract.

Javascript::share('foo, 'bar');

public function __construct(Coreplex\Bridge\Contracts\Javascript $bridge)
{
    $this->bridge = $bridge;
}

Sharing Data

To share data to the front end use the share method. You can either pass a key and value as arguments or pass an array of key value pairs. The share method can also be chained if you prefer.

$bridge->share('foo', 'bar')->share('baz', 'qux');
// OR
$bridge->share(['foo' => 'bar', 'baz' => 'qux']);

Rendering Data

To access your shared data on the front end call the renderSharedData method. This will then echo out all of the necessary scripts.

echo $bridge->renderSharedData();

bridge's People

Contributors

michaeljennings avatar georgehanson avatar midnite81 avatar

Watchers

 avatar James Cloos avatar Matthew Collison avatar  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.