Examples
The repository includes four example documents, each written twice: once as a Blade view and once in plain PHP. Comparing the two versions is a good way to see how Blade tags map to the PHP API.
| Document | What it shows | Blade | PHP |
|---|---|---|---|
| Invoice | a letterhead row, a tinted panel, line items, right-aligned totals, a footer | invoice.blade.php | invoice.php |
| Transcript | a sixty-row table across pages with its header repeated, keep-together blocks | transcript.blade.php | transcript.php |
| Report | justified prose, stat cards from an app component, an eighty-row table, a forced page break | report.blade.php | report.php |
| Form responses | all eight decorators: a card of details, a callout, numbered sections, fields, choice lists, rated statements with badges, a blockquote | responses.blade.php | responses.php |
Running them
From a checkout, install the dependencies for the package you want to try, then run the scripts from the repository root.
# Plain PHP: writes examples/core/<name>.pdf
(cd packages/core && composer install)
php examples/core/invoice.php
php examples/core/transcript.php
php examples/core/report.php
php examples/core/responses.php
# The same documents as HTML: writes examples/html/<name>.html
php examples/html/render.php
# Blade: writes examples/laravel/<name>.pdf and .html
(cd packages/laravel && composer install)
php examples/laravel/render.phpThe Blade script spins up a temporary Laravel app with Orchestra Testbench, so you don't need a full Laravel install. The sample data for the views is in examples/laravel/data.php.
The form responses example
This example shows how to build something specific to your app from the decorators. Papercut doesn't know anything about questions or answers. The view just loops over the items and picks a decorator for each one:
@foreach ($items as $item)
@if ($item['type'] === 'instruction')
<x-doc::callout type="note" :title="$item['prompt']">{{ $item['text'] }}</x-doc::callout>
@continue
@endif
<x-doc::section :number="++$n" :title="$item['prompt']" rule keep-together>
@switch($item['type'])
@case('text')
<x-doc::field placeholder="No response" lines="2">{{ $item['answer'] }}</x-doc::field>
@break
@case('choices')
<x-doc::choices :type="$item['multiple'] ? 'checkbox' : 'radio'" emphasize-selected>
@foreach ($item['options'] as $option)
<x-doc::choice :selected="in_array($option, $item['selected'], true)">{{ $option }}</x-doc::choice>
@endforeach
</x-doc::choices>
@break
@endswitch
</x-doc::section>
@endforeachAn unanswered question shows "No response" in a grey box rather than leaving a gap, and selected options get a filled checkbox and a bold label. All the colours come from the theme, so the form matches every other document the app produces.