File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 33
33
'name ' => 'shared ' ,
34
34
],
35
35
36
+ /*
37
+ * Blade directive name.
38
+ *
39
+ * By default the Blade directive named 'shared'.
40
+ *
41
+ * It means that the shared data rendering will be available in view files via `@shared`
42
+ */
43
+ 'blade_directive ' => 'shared ' ,
36
44
];
Original file line number Diff line number Diff line change 3
3
namespace Coderello \SharedData \Providers ;
4
4
5
5
use Coderello \SharedData \SharedData ;
6
- use Illuminate \Support \Facades \Blade ;
7
6
use Illuminate \Support \ServiceProvider ;
7
+ use Illuminate \View \Compilers \BladeCompiler ;
8
8
use Illuminate \Contracts \Support \DeferrableProvider ;
9
9
10
10
class SharedDataServiceProvider extends ServiceProvider implements DeferrableProvider
@@ -16,10 +16,6 @@ class SharedDataServiceProvider extends ServiceProvider implements DeferrablePro
16
16
*/
17
17
public function boot ()
18
18
{
19
- Blade::directive ('shared ' , function () {
20
- return '<?php echo app(\Coderello\SharedData\SharedData::class)->render(); ?> ' ;
21
- });
22
-
23
19
$ this ->publishes ([
24
20
__DIR__ .'/../../config/shared-data.php ' => config_path ('shared-data.php ' ),
25
21
], 'shared-data-config ' );
@@ -40,6 +36,14 @@ public function register()
40
36
$ this ->app ->singleton (SharedData::class, function () {
41
37
return new SharedData ($ this ->app ['config ' ]['shared-data ' ]);
42
38
});
39
+
40
+ $ this ->app ->extend ('blade.compiler ' , function (BladeCompiler $ bladeCompiler ) {
41
+ $ bladeCompiler ->directive ($ this ->app ['config ' ]['shared-data ' ]['blade_directive ' ], function () {
42
+ return '<?php echo app( \\' .SharedData::class.'::class)->render(); ?> ' ;
43
+ });
44
+
45
+ return $ bladeCompiler ;
46
+ });
43
47
}
44
48
45
49
/**
@@ -51,6 +55,7 @@ public function provides()
51
55
{
52
56
return [
53
57
SharedData::class,
58
+ 'blade.compiler '
54
59
];
55
60
}
56
61
}
You can’t perform that action at this time.
0 commit comments