
Laravel Shared Data Package
Share data from your backend in JavaScript with Laravel Shared Data by Coderello. The API for this package is simple:
// Facade
SharedData::put([
'post' => Post::first(),
'app' => [
'name' => config('app.name'),
'environment' => config('app.env'),
],
]);
// Helper
share([
'post' => Post::first(),
'app' => [
'name' => config('app.name'),
'environment' => config('app.env'),
],
]);
Which outputs data to JavaScript:
window.sharedData = {
post: {
content: "...",
created_at: "...",
// ...
},
app: { /* ... */ }
}
To output the configured JavaScript, add the @shared
directive to your views:
<html>
<head>
@shared
</head>
</html>
If you want to configure the JavaScript object, you can publish and change the configuration:
<?php
return ['js_namespace' => 'myCustomObjectName'];
This package has documentation available to help you get started, and you can view the source code on GitHub at coderello/laravel-shared-data.
Filed in: News / packagesNewsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.
Laravel Jobs

- Software Developer
-
Remote (US & Canada)
Alley - 😎 Laravel Developer
-
Remote
Jogg, Inc - Junior, Mid, and Senior Software Engineers. Laravel / Vue. Saint Petersburg, FL
-
Saint Petersburg, FL and Remote
ShineOn - Senior PHP Developer (Laravel)
-
Remote
The Interaction Design Foundation - Fullstack Laravel Engineer (Munich/Remote) 💻
-
Munich, Germany or Remote
AirLST GmbH
Setup Your Local Environment for Open Source Package Contributions
One of the most important steps to get started in contributing to an open-source package is to set up your local envi…
Laravel Zip Content Validator
Laravel Zip Content Validator by Orkhan Ahmadov is a custom validation rule for checking the contents of an uploaded…