PHP code example of chanthoeun / filament-document-builder
1. Go to this page and download the library: Download chanthoeun/filament-document-builder 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/ */
chanthoeun / filament-document-builder example snippets
use Chanthoeun\FilamentDocumentBuilder\DocumentBuilderPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugin(
DocumentBuilderPlugin::make()
// Optional: Customize or remove the navigation group
// ->navigationGroup('Custom Group') // Move to another group
// ->navigationGroup(false) // Remove from groups entirely
// ->navigationIcon('heroicon-o-document-text') // Change the navigation icon
);
}
public function getTotalAttribute() {
return $this->qty * $this->price;
}
public function getGrandTotalAttribute() {
return $this->items->sum('total') + $this->tax_amount;
}
use Chanthoeun\FilamentDocumentBuilder\Tables\Actions\DownloadPdfAction;
public static function table(Table $table): Table
{
return $table
// ... columns ...
->actions([
DownloadPdfAction::make('download_pdf')
->templateType('invoice') // The type string of the template you created
// Optional: Customize the filename
->filename(fn ($record) => 'invoice-' . $record->id . '.pdf')
// Optional: Pass custom data (defaults to the $record itself)
->recordData(fn ($record) => [
'name' => $record->customer_name,
'total' => $record->total_amount,
])
]);
}
use Chanthoeun\FilamentDocumentBuilder\Actions\DownloadAllPdfAction;
protected function getHeaderActions(): array
{
return [
DownloadAllPdfAction::make('download_all_pdf')
->templateType('invoice')
->records(fn () => $this->getFilteredTableQuery()->get()) // Provide the records to export
->filename('invoices-export.pdf')
];
}