Laravel
Embed the Muzekit editor in Laravel: a web route uses the Http client to open the session, and a Blade view mounts the editor.
How it works in Laravel
The route sits in the web group with the auth middleware, so auth()->user() works with Breeze, Jetstream or Fortify. Laravel checks the CSRF token on every POST in web, so the view reads it from the csrf-token meta tag and sends it as X-CSRF-TOKEN. Http::withToken adds the bearer header for you.
1. Add your secret key
Create an editor and copy its Test key (mk_test_…) from API keys in the dashboard. Put it in .env on your server:
MUZEKIT_SECRET_KEY=mk_test_…2. Open a session on your server
Opens a session for the signed-in user, in routes/web.php:
use Illuminate\Support\Facades\Http;
Route::post('/api/muzekit-session', function () {
$user = auth()->user(); // Your signed-in user: replace with your own auth
abort_unless($user, 401);
$response = Http::withToken(env('MUZEKIT_SECRET_KEY'))->post('https://api.muzekit.com/v1/sessions', [
'user' => ['id' => (string) $user->id, 'name' => $user->name, 'email' => $user->email],
'mode' => 'design',
]);
abort_unless($response->successful(), $response->status(), $response->json('error.message'));
return ['client_secret' => $response->json('client_secret')];
})->middleware('auth');3. Mount the editor
The editor (the layout needs <meta name="csrf-token" content="{{ csrf_token() }}">), in resources/views/editor.blade.php:
<div id="muzekit-editor" style="height: 720px"></div>
<script src="https://muzekit.com/sdk/v1.js"></script>
<script>
const editor = Muzekit.mount("#muzekit-editor", {
fetchClientSecret: () =>
fetch("/api/muzekit-session", { method: "POST", headers: { "X-CSRF-TOKEN": document.querySelector('meta[name="csrf-token"]').content } })
.then((r) => r.json())
.then((s) => s.client_secret),
on: {
ready: () => console.log("Muzekit editor ready"),
save: (e) => console.log("Saved", e.template, e.revision),
error: (e) => console.error("Muzekit", e.code, e.message),
},
});
</script>4. Run it
php artisan serveSign in, then open http://127.0.0.1:8000/editor. The editor loads in its container and the first session shows on your dashboard's Home. With a Test key, sessions on localhost and 127.0.0.1 are free.
Common problems
419 Page Expired
The CSRF token is missing: the layout needs the csrf-token meta tag.
Livewire re-renders over the editor
Add wire:ignore to the editor's container so Livewire leaves the iframe alone.
Inertia with Vue or React
Keep the route, and mount the editor from the component in the Vue or React example instead of a Blade view.
Notes
- Read the key through config/services.php in production (config:cache ignores env() outside config files).
- Secret key: MUZEKIT_SECRET_KEY goes in .env (or your secret store) on the server only. Never in browser code, never committed.
- Every user.id is your own id for that person: their designs and uploads follow it across sessions.
- mode: "design" opens the full editor; "fill" opens a form over a template (send template: "
<key or tpl_ id>" too). - Give the container a real height: the editor fills it.
Deploy and go live
On Forge or Vapor, set MUZEKIT_SECRET_KEY in the environment editor and read it through config/services.php, then run php artisan config:cache.
Then make a Live key (mk_live_…), add your domain to Live under Allowed domains and use Copy to Live for your templates, look and features.
Questions
Should this be a controller?
Move it to one when it grows: php artisan make:controller MuzekitSessionController --invokable gives you the file, and the body stays the same.