You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+

0 commit comments