, (*1)
Render your Elm programs from Laravel
So you want to render multiple elm programs inside a laravel application?, (*2)
This package makes it seamless., (*3)
Required: The partner Javascript library with the same name, npm i laravel-elm --save-dev, (*4)
https://github.com/loganhenson/laravel-elm, (*5)
Add the elm runner to your webpack.mix.js e.g.:
const mix = require('laravel-mix');
const elm = require('laravel-elm');
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.then(elm);
Installation
composer require tightenco/laravel-elm
Create your first Elm application
php artisan elm:create Example
Watch your elm files just like you would everything else
npm run watch
You may then use the Elm facade to view your Elm apps., (*6)
use Tightenco\Elm\Elm;
...
public function index()
{
return view('home', [
'Example' => Elm::make('Example'),
]);
}
And then render it in your view:, (*7)
{!! $Example !!}
Hello, World!, (*8)
You can even pass flags to your Elm application
You can generate a program with flags via php artisan elm:create Example --with-flags, (*9)
use Tightenco\Elm\Elm;
...
public function index()
{
return view('home', [
'Example' => Elm::make('Example', [
'value' => 'Hello, World!'
// You can pass anything you might need:
// 'csrfToken' => csrf_token(),
// 'user' => auth()->user(),
]),
]);
}
License
View the license for this repo., (*10)