PHP code example of tommasomusetti / filament-doc-studio
1. Go to this page and download the library: Download tommasomusetti/filament-doc-studio library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tommasomusetti / filament-doc-studio example snippets
use TommasoMusetti\DocStudio\DocStudioPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugins([
DocStudioPlugin::make(),
]);
}
use TommasoMusetti\DocStudio\DocumentRenderer;
use TommasoMusetti\DocStudio\Models\DocumentTemplate;
$template = DocumentTemplate::where('slug', 'quote')->firstOrFail();
$pdf = app(DocumentRenderer::class)->pdf($template); // raw PDF bytes
use TommasoMusetti\DocStudio\Contracts\DocumentDataSource;
class OrderDataSource implements DocumentDataSource
{
public static function model(): string
{
return Order::class;
}
public function fields(): array
{
return [
'customer_name' => [
'label' => 'Customer name',
'resolver' => fn (Order $order): string => $order->customer->name,
],
];
}
public function collections(): array
{
return [
'line_items' => [
'label' => 'Line items',
'columns' => ['name' => 'Item', 'qty' => 'Qty'],
'resolver' => fn (Order $order): iterable => $order->lines
->map(fn ($line) => ['name' => $line->name, 'qty' => $line->qty]),
],
];
}
public function sample(): Order
{
// The record the live preview renders against while editing.
return Order::query()->latest()->first() ?? new Order(['id' => 0]);
}
}
use Filament\Forms\Components\Builder\Block;
use Filament\Forms\Components\TextInput;
use TommasoMusetti\DocStudio\Blocks\DocumentBlock;
use TommasoMusetti\DocStudio\RenderContext;
class StampBlock extends DocumentBlock
{
public static function make(): Block
{
return Block::make('stamp')->schema([
TextInput::make('text')->