coderello / laravel-shared-data
Package for sharing data from Laravel to JavaScript.
4.0.0
2022-02-22 14:31 UTC
Requires
- php: ^8.0
- ext-json: *
- illuminate/support: ^9.0
Requires (Dev)
- orchestra/testbench: ^7.0
This package is auto-updated.
Last update: 2026-06-15 13:58:58 UTC
README
✨ 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 coderello/laravel-shared-data
-
Include the
@shareddirective 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.