PHPackages                             mnvx/eloquent-print-form - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. mnvx/eloquent-print-form

ActiveLibrary[Payment Processing](/categories/payments)

mnvx/eloquent-print-form
========================

Print form processor for Eloquent

1.0.1(5y ago)296124MITPHPPHP ^7.4

Since Nov 10Pushed 2y ago3 watchersCompare

[ Source](https://github.com/mnvx/eloquent-print-form)[ Packagist](https://packagist.org/packages/mnvx/eloquent-print-form)[ Docs](https://github.com/mnvx/eloquent-print-form)[ RSS](/packages/mnvx-eloquent-print-form/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (6)Dependencies (3)Versions (8)Used By (0)

Print forms for Eloquent
========================

[](#print-forms-for-eloquent)

Easy way to generate docx print forms of invoices, contracts and other documents.

Usage
-----

[](#usage)

Installation

```
composer require mnvx/eloquent-print-form
```

Declare models for Eloquent.

Create print form (docx file) using next syntax.

- `${field_name}` - standard field
- `${entity.field_name}` - field from linked entity
- `${entity.field_name|date}` - format field as date
- `${entity.field_name|date|placeholder}` - format field as date and replace to "\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_" if field is empty
- `${entity1.entity2.field_name}` - field from linked entity through one table
- `${entities.field_name}` - for table data

As you may see, it is possible to use pipes, for example: `|date`, `|date|placeholder`. Supported pipes are:

- `placeholder` - replaces empty variable to "\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_".
- `date` - format date
- `dateTime` - format date time
- `int` - format int value
- `decimal` - format decimal value

It is possible also to specify custom pipes.

Generate print form for specified entity

```
$entity = Contract::find($id);
$printFormProcessor = new PrintFormProcessor();
$templateFile = resource_path('path_to_print_forms/your_print_form.docx');
$tempFileName = $printFormProcessor->process($templateFile, $entity);
```

Examples
--------

[](#examples)

### Basic example

[](#basic-example)

For example, if there are next models in project.

```
use Illuminate\Database\Eloquent\Model;

/**
 * @property string $number
 * @property string $start_at
 * @property int $customer_id
 * @property Customer $customer
 * @property ContractAppendix[] $appendixes
 */
class Contract extends Model
{

    public function customer()
    {
        return $this->belongsTo(Customer::class);
    }

    public function appendixes()
    {
        return $this->hasMany(ContractAppendix::class);
    }
}

/**
 * @property string $name
 * @property CustomerCategory $category
 */
class Customer extends Model
{
    public function category()
    {
        return $this->belongsTo(CustomerCategory::class);
    }

}

/**
 * @property string $number
 * @property string $date
 * @property float $tax
 */
class ContractAppendix extends Model
{

    public function items()
    {
        return $this->hasMany(ContractAppendixItem::class, 'appendix_id');
    }

    public function getTaxAttribute()
    {
        $tax = 0;
        foreach ($this->items as $item) {
            $tax += $item->total_amount * (1 - 100 / (100+($item->taxStatus->vat_rate ?? 0)));
        }
        return $tax;
    }
}
```

Example of Laravel's controller action for printing contract.

```
public function downloadPrintForm(FormRequest $request)
{
    $id = $request->get('id');
    $entity = Contract::find($id);
    $printFormProcessor = new PrintFormProcessor();
    $templateFile = resource_path('path_to_print_forms/your_print_form.docx');
    $tempFileName = $printFormProcessor->process($templateFile, $entity);
    $filename = 'contract_' . $id;
    return response()
        ->download($tempFileName, $filename . '.docx')
        ->deleteFileAfterSend();
}
```

Example of docx template

---

Contract number: ${number|placeholder}
Contract date: ${start\_at|date|placeholder}
Customer: ${customer.name}
Customer category: ${customer.category.name|placeholder}

Appendixes:

Row numberAppendix numberAppendix tax${appendixes.#row\_number}${appendixes.number}${appendixes.tax}---

Example of generated document

---

Contract number: F-123
Contract date: 12.04.2012
Customer: IBM
Customer category: \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

Appendixes:

Row numberAppendix numberAppendix tax1A-112342A-1.103B-110---

### How to specify custom pipes

[](#how-to-specify-custom-pipes)

```
class CustomPipes extends \Mnvx\EloquentPrintForm\Pipes
{
    // Override
    public function placeholder($value)
    {
        return $value ?: "NO DATA";
    }

    // New pipe
    public function custom($value)
    {
        return "CUSTOM";
    }
}

$entity = Contract::find($id);
$pipes = new CustomPipes();
$printFormProcessor = new PrintFormProcessor($pipes);
$templateFile = resource_path('path_to_print_forms/your_print_form.docx');
$tempFileName = $printFormProcessor->process($templateFile, $entity);
```

### How to specify custom processors for some variables

[](#how-to-specify-custom-processors-for-some-variables)

Example of custom processor for variable `${custom}`.

```
$tempFileName = $printFormProcessor->process($templateFile, $entity, [
    'custom' => function(TemplateProcessor $processor, string $variable, ?string $value) {
        $inline = new TextRun();
        $inline->addText('by a red italic text', array('italic' => true, 'color' => 'red'));
        $processor->setComplexValue($variable, $inline);
    },
]);
```

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~195 days

Recently: every ~293 days

Total

7

Last Release

925d ago

Major Versions

0.5.4 → 7.2.x-dev2020-11-27

PHP version history (2 changes)1.0.0PHP ^7.4

0.5.3PHP ^7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/2bac4bded42026d8fd5726df11002c08442b34b40eed209223a73a784a559f34?d=identicon)[mnvx](/maintainers/mnvx)

---

Top Contributors

[![mnvx](https://avatars.githubusercontent.com/u/829880?v=4)](https://github.com/mnvx "mnvx (6 commits)")

---

Tags

worddocxinvoicedocumentcontractprint form

### Embed Badge

![Health badge](/badges/mnvx-eloquent-print-form/health.svg)

```
[![Health](https://phpackages.com/badges/mnvx-eloquent-print-form/health.svg)](https://phpackages.com/packages/mnvx-eloquent-print-form)
```

###  Alternatives

[mollie/laravel-cashier-mollie

Laravel Cashier provides an expressive, fluent interface to Mollie's subscription billing services.

179223.2k1](/packages/mollie-laravel-cashier-mollie)[anourvalar/office

Generate documents from existing Excel &amp; Word templates | Export tables to Excel (Grids)

23999.6k](/packages/anourvalar-office)[flarum/core

Delightfully simple forum software.

211.5M2.4k](/packages/flarum-core)[lapaliv/laravel-bulk-upsert

1534.2k](/packages/lapaliv-laravel-bulk-upsert)[alajusticia/laravel-logins

Session management in Laravel apps, user notifications on new access, support for multiple separate remember tokens, IP geolocation, User-Agent parser

2115.6k](/packages/alajusticia-laravel-logins)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
