- Does jbzoo/mermaid-php render diagrams to SVG or PNG, or only generate Mermaid text?
- The package's stated purpose is to generate Mermaid definition strings through a fluent PHP API. That output is Mermaid source, which you then render client-side with Mermaid.js or server-side with a tool like mmdc or Kroki. Check the README to confirm whether any optional rendering backend ships with the package, since that distinction changes your integration plan significantly.
- How do I install jbzoo/mermaid-php in a Laravel application?
- Install it with Composer using composer require jbzoo/mermaid-php. Small utility packages like this often need no service provider, but check the README for Laravel auto-discovery details. You can then instantiate the builder classes directly in a controller, artisan command, or queued job. Keep the package behind your own wrapper class so call sites are not coupled to its API.
- Which PHP and Laravel versions does jbzoo/mermaid-php support?
- The package is Composer-installable and framework-agnostic, so it can be used in Laravel projects that satisfy its PHP constraint. Exact PHP and Laravel version support is declared in the package's composer.json and README, so verify those before adding it to an existing app. Pin the version in composer.json rather than letting it float. Run your test suite after install to catch any constraint conflicts.
- How do I render a Mermaid diagram to SVG or PNG from a Laravel app?
- Generate the Mermaid definition with jbzoo/mermaid-php, then pass that string to a renderer. Common options are Mermaid.js in the browser, the Mermaid CLI (mmdc) in a Node and Chromium container, or a self-hosted Kroki service. In Laravel, do this in a queued job or artisan command and store the resulting SVG or PNG in object storage. Avoid rendering in a synchronous web request because headless Chromium is CPU- and memory-heavy.
- Can jbzoo/mermaid-php generate flowcharts, sequence diagrams, and class diagrams?
- Yes. The package targets the Mermaid DSL, which covers flowcharts, sequence diagrams, class diagrams, ER diagrams, and Gantt charts. The fluent API lets you compose nodes, edges, participants, and relationships without hand-writing the Mermaid syntax. Output is Mermaid text that you render with any Mermaid-compatible renderer.
- Is jbzoo/mermaid-php suitable for a production Laravel request path?
- The package itself is a lightweight Composer dependency, but any diagram rendering you add around it is not request-path friendly. Headless Chromium rendering is CPU-heavy, needs Node and system libraries in your container image, and can be flaky under load. Put rendering behind a queued job and cache artifacts by a hash of the diagram source and renderer version. That keeps your web and API latency predictable.
- How should I test Mermaid diagram output generated by jbzoo/mermaid-php?
- Unit-test the generated Mermaid string rather than the rendered image, since string output is deterministic and fast to assert. Snapshot-test a few representative diagrams such as flowchart, sequence, and ER so refactors do not silently change syntax. If you also test rendering, do it in a separate integration suite with a pinned Node and Chromium image. Byte-determinism of rendered SVG varies between Mermaid versions, so do not rely on it without pinning.
- What are the alternatives to jbzoo/mermaid-php for diagrams in Laravel?
- You can template Mermaid strings yourself, invoke the Mermaid CLI (mmdc) directly, use a self-hosted Kroki instance, or render Mermaid.js in the browser. The package mainly saves you from manual string building, so evaluate whether that API convenience is worth the extra dependency. Wrapping your own DiagramRenderer interface lets you swap between these options without changing call sites.
- Is jbzoo/mermaid-php actively maintained, and how tightly does it pin Mermaid versions?
- It is a niche, effectively single-maintainer package, so treat maintenance and release cadence as a risk to review rather than assume. Mermaid's DSL and rendering internals change across major versions, and thin wrappers often lag or pin hard. Check the repository's recent commits, releases, and composer.json constraints before committing. Pin the package version exactly and own the upgrade path yourself.
- How do I cache generated Mermaid diagrams in Laravel?
- Key the cache by a hash of the Mermaid source plus the renderer and Mermaid versions, and store the SVG or PNG in Laravel's cache or object storage. Use a queued job to render on a cache miss and return the cached artifact on a hit. Invalidate entries by changing the version component of the key when you upgrade the renderer. This avoids repeated headless Chromium runs and keeps rendering costs bounded.