coderello / laravel-shared-data by coderello

Package for sharing data from Laravel to JavaScript.
70,291
324
5
Package Data
Maintainer Username: coderello
Package Create Date: 2019-03-18
Package Last Update: 2023-02-01
Home Page: https://coderello.com/docs/laravel-shared-data/1.0/sharing-data
Language: PHP
License: MIT
Last Refreshed: 2024-04-22 15:03:45
Package Statistics
Total Downloads: 70,291
Monthly Downloads: 538
Daily Downloads: 18
Total Stars: 324
Total Watchers: 5
Total Forks: 20
Total Open Issues: 2

✨ Introduction

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

📖 Documentation

For installation instructions and usage details, please take a look at the official documentation.

🚀 Quick start

  • Install the package:

    composer require coderello/laravel-shared-data
    
  • Include the @shared directive into your blade layout before all scripts.

  • Share the data from within Laravel:

    share(['user' => $user, 'title' => $title]);
    
  • Access the data from the JavaScript directly:

    const user = window.sharedData.user;
    const title = window.sharedData.title;
    
  • Or using the built-it global helper:

    const user = shared('user');
    const title = shared('title');
    

💖 Support the development

Do you like this project? Support it by donating:

Laravel Shared Data is open-sourced software licensed under the MIT license.