Skip to content
📦 An easy way to share the data from your backend to the JavaScript.
Branch: master
Clone or download
hivokas Merge pull request #6 from klimov-paul/refactor-config
Refactor `SharedData` configuration
Latest commit 212bb66 Jul 16, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
src refactor configuration allowing creation of standalone `SharedData` i… Jul 15, 2019
tests
.gitattributes
.gitignore Initial commit Mar 18, 2019
.styleci.yml
.travis.yml refactor configuration allowing creation of standalone `SharedData` i… Jul 15, 2019
CONTRIBUTING.md
LICENSE.md Initial commit Mar 18, 2019
README.md add unit tests and Travis support Jul 11, 2019
composer.json
phpunit.xml.dist

README.md

Laravel Shared Data

Laravel Shared Data provides an easy way to share the data from your backend to the JavaScript.

Latest Stable Version Total Downloads Build Status

Installation

You can install this package via composer using this command:

composer require coderello/laravel-shared-data

The package will automatically register itself.

Usage

First of all, you need to include this line before all of your <script> tags in you base blade layout in order to make the shared data available in all of those scripts.

{!! shared()->render() !!}

Now you can share any data you want from any part or your application (middleware, controller, service provider etc.)

use Coderello\SharedData\Facades\SharedData;

public function index()
{
    SharedData::put([
        'user' => auth()->user(),
        'post' => Post::first(),
        'username' => '@hivokas',
    ]);
    
    // or
    
    share([
        'user' => auth()->user(),
        'post' => Post::first(),
        'username' => '@hivokas',
    ]);
}

And get this data on the frontend side from window.sharedData (use can modify the namespace in the config file).

Shared Data in JS

Testing

You can run the tests with:

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

License

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

You can’t perform that action at this time.