Download the PHP package beziworld/laravel-docx-templates without Composer
On this page you can find all versions of the php package beziworld/laravel-docx-templates. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download beziworld/laravel-docx-templates
More information about beziworld/laravel-docx-templates
Files in beziworld/laravel-docx-templates
Package laravel-docx-templates
Short Description Word (.docx) templates for Laravel on PHPWord: filesystem disks, variables, blocks, table rows, images, Eloquent models, safe escaping, downloads and PDF through LibreOffice
License MIT
Homepage https://github.com/beziworld/laravel-docx-templates
Informations about the package laravel-docx-templates
Laravel DOCX Templates
Fill Word (.docx) templates in Laravel: contracts, invoices, certificates, letters. A Laravel layer over
PHPWord's TemplateProcessor:
- templates on any filesystem disk (local, S3, ...), output stored on a disk, saved locally or returned as a
download or inline response (
Responsable, so a route can return the document directly) - values with dot notation (
${customer.address.city}), blocks that are kept, removed or repeated, table rows cloned per item, images (local file, disk or bytes) and generated tables - data from arrays, Eloquent models (through
toArray()keys, so$hiddenattributes never reach a document), collections and plain objects - typed template definitions: one class per document type with typed constructor arguments, required placeholders and a file name
- Blade-like escaping: every value is XML-escaped like
{{ }};Raw/Htmlablevalues are inserted as is, like{!! !!}; forbidden control characters removed; new lines and tabs become Word breaks - strict mode: rendering fails when placeholders are left unresolved, listing them
- optional PDF conversion with a configured LibreOffice binary: argument list without a shell, timeout, an
isolated user profile per conversion, testable with
Process::fake() docx:variables(list the placeholders of a template) andmake:docx-templateArtisan commands
Polska wersja dokumentacji
Why this package
PHPWord has 49 million downloads, but its Laravel wrappers are small. The most downloaded ones on Packagist
(November 2026): novay/laravel-word-template 22k, santwer/exporter 3.7k, the rest below 1k.
santwer/exporter is a capable package built around export classes with concerns (in the style of Laravel
Excel), with charts, checkboxes, batch exports and PDF through LibreOffice. It resolves templates from absolute
paths or storage_path(). This package takes a different route:
| santwer/exporter | this package | |
|---|---|---|
| Template location | absolute path or storage_path() |
any filesystem disk, local path or bytes |
| Output | download, file, PDF | disk (store()), local file, download, inline, Responsable, PDF |
| Document definition | export class with concerns | TemplateDefinition with typed constructor, required() placeholders |
| Unresolved placeholders | not documented | strict mode fails and lists them |
| Eloquent hidden attributes | not documented | never rendered (toArray() keys) |
| PDF in tests | needs LibreOffice | Process::fake() |
| Charts, checkboxes, batch exports | yes | no |
novay/laravel-word-template is a fluent wrapper with values, images, loops, watermarks and merging, reading
templates from paths. enflow/document-replacer (39k, framework-agnostic) replaces values and converts through
unoserver.
Installation
Requirements: PHP 8.3+, Laravel 12 or 13, ext-zip, ext-dom. LibreOffice only for PDF.
Template syntax
Placeholders use the PHPWord syntax, typed in Word as plain text:
| In the template | Filled with |
|---|---|
${number}, ${customer.address.city} |
a value (dot notation reads nested data) |
${discount} ... ${/discount} (each marker in its own paragraph) |
a block: kept, removed or repeated |
${item.name} in a table row |
the row is repeated per item |
${logo} or ${logo:120:60} |
an image |
${summary} alone in a paragraph |
a generated table |
Word sometimes splits text into several runs while you type; PHPWord repairs most split placeholders. Run
php artisan docx:variables invoice.docx to see the placeholders the package finds.
Filling a template
Shortcuts on the template: ->store(), ->save(), ->download(), ->pdf().
Lists and booleans in the data fill blocks automatically: with ['discount' => false] the
${discount}...${/discount} block disappears, with a list it is repeated. An empty list removes a block or a
table row.
Other template sources:
Values and escaping
| Value | Written as |
|---|---|
| string, int, float | escaped text (&, <, >, quotes), like Blade {{ }} |
null |
empty |
bool |
booleans.true / booleans.false from the config (1 / empty, like Blade) |
DateTimeInterface (also Eloquent date casts) |
date_format from the config |
| backed enum / unit enum | value / name |
Stringable |
its string |
Raw::xml('...'), DocxTemplates::raw(), any Htmlable |
inserted without escaping, like {!! !!} |
| array or list | only through blocks, rows or tables; otherwise InvalidValue |
Characters that XML 1.0 forbids are removed and invalid UTF-8 is replaced, so user input cannot corrupt the
document. New lines become <w:br/> and tabs <w:tab/> (line_breaks in the config). PHPWord's own global
output escaping setting is left untouched and restored after rendering.
Raw markup goes inside a w:t element, so it usually closes and reopens the run, for example
Raw::xml('</w:t><w:br/><w:t>'). Never wrap user input in Raw.
Eloquent models
with($model) reads the keys of $model->toArray(), which means visible attributes, $appends accessors and
loaded relations, and takes their values from getAttribute() so that casts keep their type (dates are formatted
with date_format). Attributes in $hidden are never available to a template. Load the relations a template
needs before rendering ($invoice->load('customer', 'items')).
Template definitions
One class per document type keeps the template, the data mapping and the requirements together:
Other hooks: disk() (template disk) and strict().
The converter runs soffice --headless --norestore --nolockcheck --nodefault -env:UserInstallation=<temporary profile> --convert-to pdf --outdir <temporary directory> <file> through Laravel's Process with the configured
timeout. The command is an argument list (no shell); the temporary profile is removed afterwards, so parallel
queue workers do not share one LibreOffice instance. A non-zero exit code, a timeout or a missing output file raise
ConversionFailed with LibreOffice's error output. Bind your own Beziworld\DocxTemplates\Pdf\PdfConverter to use
another engine (Gotenberg, unoserver).
In tests:
Artisan
Errors
| Exception | When |
|---|---|
TemplateNotFound |
the template is missing on the disk or path, or is not a .docx (ZIP with word/document.xml) |
UnresolvedPlaceholders |
strict mode and placeholders left; placeholders() lists them |
TemplateMismatch |
a placeholder from require() / required() is missing in the template |
InvalidValue |
a value without a text form, an array used as a value, an image that is missing or not an image |
RenderingFailed |
PHPWord failed, a row anchor is missing, a file cannot be written |
ConversionFailed |
LibreOffice failed, timed out or wrote no PDF |
InvalidConfiguration |
invalid timeout or temporary directory |
All exceptions extend Beziworld\DocxTemplates\Exceptions\DocxTemplatesException.
Limits
- Placeholders inside headers and footers are filled as values and images; blocks and table rows work in the document body only (PHPWord limitation).
- Nested blocks (a block inside a repeated block) are not supported.
- Templates are trusted input: they are authored by you, not uploaded by users.
- PDF output quality depends on LibreOffice and the fonts installed on the server.
Development
Test templates are generated at runtime with PHPWord; LibreOffice is faked with Process::fake().
Author
Created and maintained by Kamil Ćwiertnia, beziworld.eu.
- E-mail: [email protected]
- Issues: GitHub issues
Need an integration? Get in touch through beziworld.eu.
License
MIT. See LICENSE.md. PHPWord is licensed under LGPL-3.0 by its authors. This package is not affiliated with or endorsed by the PHPOffice project, Microsoft or The Document Foundation.
All versions of laravel-docx-templates with dependencies
ext-dom Version *
ext-zip Version *
illuminate/console Version ^12.0|^13.0
illuminate/contracts Version ^12.0|^13.0
illuminate/filesystem Version ^12.0|^13.0
illuminate/http Version ^12.0|^13.0
illuminate/process Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
phpoffice/phpword Version ^1.4