amgrade/bifrost

Bridge between PHP and JS variables

dev-main 2023-11-07 03:59 UTC

This package is auto-updated.

Last update: 2024-04-07 04:54:30 UTC


README

This package deleloped to be like a bridge between PHP and JavaScript.

Installation

composer require amgrade/bifrost

Usage

// Somewhere in your controller class.
\AMgrade\Bifrost\Bifrost::push(['foo' => 'bar', 'baz' => 'foo']);
// Later in your view (e.g. Laravel Blade).
<head>
...
{!! \AMgrade\Bifrost\Bifrost::toHtml() !!}
</head>
// In your JS app.
console.log(window.Bifrost.foo);
console.log(window.Bifrost.baz);

Configuration

You can pass your own namespace to prevent name conflicts.

<head>
...
{!! \AMgrade\Bifrost\Bifrost::toHtml('YOUR_NAMESPACE') !!}
</head>
// In your JS app.
console.log(window.YOUR_NAMESPACE.foo);
console.log(window.YOUR_NAMESPACE.baz);