Skip to content

Instantly share code, notes, and snippets.

@felixdorn
Created March 18, 2021 22:03
Show Gist options
  • Save felixdorn/7b57da4b14aefbed53d430510e7bd40e to your computer and use it in GitHub Desktop.
Save felixdorn/7b57da4b14aefbed53d430510e7bd40e to your computer and use it in GitHub Desktop.
Blade::directive('alpine', function (string $variables) {
return <<<PHP
<?php
\$data = array_combine(
array_map(
fn (\$variable) => str_replace('$', '', \$variable),
explode(',', '$variables')
),
[$variables]
);
echo trim(
str_replace(["'", '"'], ["\'", "'"], json_encode(\$data)),
'{}'
);
?>
PHP;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment