Skip to content

Commit c5abeb3

Browse files
committed
feat: add inertia directives
1 parent 2ce484c commit c5abeb3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Blade.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,22 @@ protected function setupDefaultDirectives()
261261
return "<?php echo ViewsPath($expression); ?>";
262262
});
263263

264+
$this->compiler()->directive('route', function ($expression) {
265+
return "<?php echo app()->route($expression)['path'] ?? ''; ?>";
266+
});
267+
268+
$this->compiler()->directive('viteReactRefresh', function ($expression) {
269+
return "<?php echo \Leaf\Vite::reactRefresh(); ?>";
270+
});
271+
272+
$this->compiler()->directive('inertiaHead', function ($expression) {
273+
return '<?php if (!isset($__inertiaSsrDispatched)) { $__inertiaSsrDispatched = true; $__inertiaSsrResponse = (new \Leaf\Inertia\Ssr\Gateway())->dispatch($page); } if ($__inertiaSsrResponse) { echo $__inertiaSsrResponse->head; } ?>';
274+
});
275+
276+
$this->compiler()->directive('inertia', function ($expression) {
277+
return '<?php if (!isset($__inertiaSsrDispatched)) { $__inertiaSsrDispatched = true; $__inertiaSsrResponse = (new \Leaf\Inertia\Ssr\Gateway())->dispatch($page); } if ($__inertiaSsrResponse) { echo $__inertiaSsrResponse->body; } else { ?><div id="app" data-page="<?php echo e(json_encode($page)); ?>"></div><?php } ?>';
278+
});
279+
264280
$this->directive('toastContainer', function ($expression) {
265281
return <<<HTML
266282
<div class="relative w-auto h-auto" x-data>

0 commit comments

Comments
 (0)