Skip to content

Commit 18f93b9

Browse files
author
Ilya Sakovich
authored
readme
1 parent d3aa167 commit 18f93b9

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,47 @@ composer require coderello/laravel-shared-data
1212

1313
The package will automatically register itself.
1414

15+
## Usage
16+
17+
First of all, you need to include this line before all of your `<script>` tags in you base blade layout in order to make the shared data available in all of those scripts.
18+
19+
```php
20+
{!! shared()->render() !!}
21+
```
22+
23+
Now you can share any data you want from any part or your application (middleware, controller, service provider etc.)
24+
25+
```php
26+
use Coderello\SharedData\Facades\SharedData;
27+
28+
public function index()
29+
{
30+
SharedData::put([
31+
'user' => auth()->user(),
32+
'post' => Post::first(),
33+
'username' => '@hivokas',
34+
]);
35+
36+
// or
37+
38+
share([
39+
'user' => auth()->user(),
40+
'post' => Post::first(),
41+
'username' => '@hivokas',
42+
]);
43+
}
44+
```
45+
46+
And get this data on the frontend side from `window.sharedData` (use can modify the namespace in the config file).
47+
48+
![Shared Data in JS](http://i.imgur.com/v21h7NN.png)
49+
50+
51+
52+
53+
54+
55+
1556
## Testing
1657

1758
You can run the tests with:

0 commit comments

Comments
 (0)