Looking to hire Laravel developers? Try LaraJobs

laravel-shared-data maintained by lenius

Description
Package for sharing data from Laravel to JavaScript.
Last update
2025/04/04 20:50 (dev-main)
License
Links
Downloads
2 835

Comments
comments powered by Disqus

Laravel Shared Data

✨ Introduction

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

🚀 Quick start

  • Install the package

    composer require lenius/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');
    

📖 License

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