lenius / laravel-shared-data
Package for sharing data from Laravel to JavaScript.
Installs: 1 949
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- ext-json: *
- illuminate/support: ^9.0|^10|^11
Requires (Dev)
- orchestra/testbench: ^7.0|^8.0|^9.0
- phpunit/phpunit: ^9.0|^10.1
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 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.