Installation
composer require tomatophp/filament-docs
Publish the package assets and config:
php artisan vendor:publish --provider="TomatoPHP\FilamentDocs\FilamentDocsServiceProvider" --tag="filament-docs-config"
php artisan vendor:publish --provider="TomatoPHP\FilamentDocs\FilamentDocsServiceProvider" --tag="filament-docs-migrations"
php artisan migrate
Register the Plugin
Add to app/Providers/Filament/AdminPanelProvider.php:
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
\TomatoPHP\FilamentDocs\FilamentDocsPlugin::make(),
]);
}
First Use Case
Create a template via the Templates section in Filament. Use the Tiptop Editor to design your document (e.g., a contract or invoice). Define dynamic variables (e.g., {client_name}) that will be replaced during generation.
Template Creation
{company_address}, {invoice_total}) using the template builder.Dynamic Variable Injection
use TomatoPHP\FilamentDocs\Facades\FilamentDocs;
FilamentDocs::setVar('client_name', 'John Doe');
FilamentDocs::setVar('invoice_total', 1000.00);
Document Generation
Relation Management
Client, Invoice) via Filament’s relation manager.Client record for tracking.Bulk Operations
Customize Variables Programmatically Extend the facade to add domain-specific variables:
FilamentDocs::extendVars(function ($vars) {
$vars['tax_rate'] = config('company.tax_rate');
});
Hook into Generation Events Listen for document generation events to log or process data:
FilamentDocs::listen('generating', function ($document) {
// Log or modify document data before export
});
PDF Customization Override the PDF renderer by publishing the package’s views:
php artisan vendor:publish --provider="TomatoPHP\FilamentDocs\FilamentDocsServiceProvider" --tag="filament-docs-views"
Then extend resources/views/vendor/filament-docs/pdf.blade.php.
Localization Translate template variables and UI text via Filament’s localization system:
FilamentDocs::setTranslation('client_name', 'Nom du client');
Variable Scope Conflicts
invoice_{client_id}_total).Editor Limitations
PDF Rendering Issues
storage/logs/filament-docs.log for rendering errors.Migration Conflicts
documents table, run migrations after publishing the package’s migrations to avoid schema conflicts.Caching Quirks
php artisan cache:clear) if changes to templates or variables aren’t reflected:
FilamentDocs::clearCache();
Log Variables Dump variables before generation:
FilamentDocs::listen('generating', function ($document) {
\Log::debug('Vars:', $document->vars);
});
Inspect Templates View the raw template HTML via the source code button in the Tiptop Editor or by querying the database:
$template = \TomatoPHP\FilamentDocs\Models\Template::find(1);
\Log::info($template->content);
Test with Minimal Templates
Start with a single variable (e.g., {test}) to isolate issues.
Custom Storage Override the default storage path for generated documents:
config(['filament-docs.storage.path' => storage_path('app/docs')]);
Add Document Types
Extend the Document model to support metadata (e.g., document_type):
use TomatoPHP\FilamentDocs\Models\Document;
Document::addGlobalScope('type', function (Builder $builder, string $type) {
$builder->where('metadata->type', $type);
});
Webhook Triggers Dispatch events after generation to notify external systems:
FilamentDocs::listen('generated', function ($document) {
// Send webhook or update CRM
});
Batch Processing Use Laravel queues to generate documents asynchronously:
FilamentDocs::generateLater($templateId, $vars);
How can I help you explore Laravel packages today?