jawira/plantuml
Generate UML diagrams with PlantUML from PHP and Laravel. jawira/plantuml wraps the PlantUML tool and server to render diagrams from text, making it easy to integrate UML generation into your app, CLI scripts, or build pipelines.
Install the package with composer require jawira/plantuml. The first call to PlantUml::generate() will auto-download the PlantUML JAR into storage/app/plantuml. Ensure Java 8+ is installed (java -version), as the package relies on the JRE at runtime. Your first quick win: generate a PNG from inline PlantUML:
use Jawira\PlantUml\PlantUml;
$uml = "@startuml\nAlice -> Bob: Hello\n@enduml";
$png = PlantUml::generate($uml);
file_put_contents('public/diagram.png', $png);
Start by checking storage/app/plantuml/ for the JAR and inspecting log files if generation fails.
php artisan plantuml:render) that reads .puml files from resources/diagrams/ and outputs SVG/PNG to public/diagrams/. Useful for internal architecture visualization.PlantUml instance with custom options (e.g., format, timeout), injected into jobs or controllers:
$this->app->singleton(\Jawira\PlantUml\PlantUml::class, function () {
return (new \Jawira\PlantUml\PlantUml)
->setFormat('svg')
->setOption('-timeout', '120');
});
phpunit.xml or GitHub Actions:
php artisan plantuml:generate-all # custom command
Commit generated assets or deploy them as part of docs.@plantuml Blade directive that caches and renders diagrams on-demand using Illuminate\Support\Facades\Cache.md5($uml)) before regenerating—ideal for reducing CI compute time.java in PATH, exec() calls fail silently or throw cryptic errors—always validate which java in CLI and web SAPI contexts.php artisan vendor:publish --provider="Jawira\PlantUml\PlantUmlServiceProvider" (if defined) or manually copy config/plantuml.php from the package to set JAR path, format defaults, or Java opts.C:\Program Files\Java\...)—PlantUML fails to quote arguments correctly. Symlink to a simple path like C:\plantuml\java.exe.generate() returns binary content. Use getRawOutput() to catch PlantUML stderr (e.g., syntax errors, Graphviz missing). Wrap in try/catch for PlantUmlException.memory_limit or offload to queued jobs (Dispatchable, InteractsWithQueue).getExecutablePath() to log full command lines (e.g., java -jar ... -graphvizdot /usr/bin/dot ...) using Laravel’s Log::debug().How can I help you explore Laravel packages today?