php-dominicana/laravel-model-export
To quickly leverage the new PDF export feature, install the package via Composer:
composer require vendor/package-name
Then, publish the package's configuration (if applicable) and assets:
php artisan vendor:publish --provider="Vendor\PackageName\PackageServiceProvider" --tag="config"
php artisan vendor:publish --provider="Vendor\PackageName\PackageServiceProvider" --tag="assets"
For your first use case, generate a PDF from an existing Eloquent model or collection:
use Vendor\PackageName\Facades\PackageName;
$pdf = PackageName::query(Model::class)
->where('active', true)
->exportToPdf();
The package will automatically handle view rendering and PDF generation using the default template (located at resources/views/vendor/package-name/pdf/default.blade.php).
exportToPdf() method onto an Eloquent query builder instance:
$pdf = Model::where('status', 'published')->exportToPdf();
PackageName::exportToPdf()->setTemplate('custom.template');
PackageName::exportToPdf()->with(['custom_data' => 'value']);
PDF object to:
$pdf->download('filename.pdf')$pdf->stream('filename.pdf')$pdf->save(storage_path('app/filename.pdf'))$pdf = Model::paginate(50)->exportToPdf();
package.pdf.exporting and package.pdf.exported events to modify behavior:
event(new ExportingEvent($query, $options));
dispatch(new ExportPdfJob(Model::class, $options));
resources/views/vendor/package-name/ or the package will fall back to the default.position: fixed). Test styles in the default template first.config(['package-name.debug' => true]);
dd($pdf->getViewData()) to inspect data passed to the template before rendering.try {
$pdf = Model::exportToPdf();
} catch (\Vendor\PackageName\Exceptions\ExportException $e) {
Log::error($e->getMessage());
}
PackageName::setPdfEngine(new \Snappy());
PackageName::exportToPdf()->setFilename(fn() => 'export_'.now()->format('Y-m-d').'.pdf');
$pdf->exportToPdf()->then(function($pdf) {
// Send email with PDF attachment
});
How can I help you explore Laravel packages today?