Download the PHP package saroven/laravel-reportify without Composer
On this page you can find all versions of the php package saroven/laravel-reportify. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-reportify
Reportify ๐
Reportify is a unified, high-performance report generation and document export engine for Laravel applications. Easily stream or export PDFs (via mPDF), Excel (.xlsx), CSV, TXT, and ZIP archives using clean Laravel syntax, event-driven background queues, and customizable Blade templates.
๐ฎ Demo Application
A complete working demo showing User Directory exports, PDF streaming, and a full Download Manager lifecycle implementation is available at:
๐ https://github.com/saroven/laravel-reportify-demo
๐ฆ Features
- ๐ Multi-Format Export Engine: Generate PDF, Excel (.xlsx), CSV, TXT, and ZIP packages.
- โก Synchronous PDF Streaming: Directly stream formatted PDF documents in the browser tab.
- ๐ Event-Driven Background Queues: Offload heavy exports to queue workers with native Laravel events (
ExportStarted,ExportCompleted,ExportFailed). - ๐งฉ PDF Chunking & Merging: Automatically chunk large datasets into smaller PDF files and merge them via
PDFMerger. - ๐จ Customizable Blade Templates: Configurable PDF headers, page footers, print dates, authenticated user stamps, and page numbers (
Page X of Y). - ๐ Artisan Generator Command:
php artisan reportify:make {name}generates cleanReportableexport classes. - ๐ฎ Exportable Controller Trait:
HasReportifytrait enables 1-line export handling in controllers ($this->exportReport()). - ๐ Blade UI Component: Drop-in export action buttons
<x-reportify-buttons />and helper scripts<x-reportify-scripts />.
๐ About
This package started from a recurring problem: every Laravel project with reporting needs ends up with the same scattered code โ mPDF calls in controllers, memory crashes on large datasets, separate queue jobs per format, and footer/header logic copied between files.
Reportify pulls all of that into one place. You define what data to export via a Reportable class, pick a format, and the rest is handled โ chunking for large PDFs, queuing, event dispatching, Blade templates for headers and footers, and ZIP packaging. The same interface works for every format, so there's nothing new to learn when you add a second export type to a controller.
A few things worth knowing before you start:
pdfChunkis what you want for anything over a few thousand rows. It splits the data, renders parts separately, then merges them โ so mPDF never has to hold the full dataset in memory.- Exports are queued by default. If your server doesn't run a queue worker, set
REPORTIFY_FORCE_SYNC=trueand everything runs inline. - The
Reportableinterface has one method. If your controller already has the data, you can implement it directly on the controller and skip the separate export class entirely. - Header margins are auto-calculated from your header HTML. If the result is off,
headerMarginandadditionalHeaderMarginin$additionalDatalet you correct it per-report without touching the config.
โก Installation
Install the package via Composer:
Publish the configuration file and Blade views (optional):
๐ Quick Start
1. Make any Controller Exportable
Implement the Reportable interface and use the HasReportify trait on your controller:
2. Generate Dedicated Export Classes
Generate a dedicated Reportable export class using the Artisan generator command:
This creates app/Exports/UserExport.php:
Dispatch background exports manually using ProcessReportJob:
3. Synchronous PDF Streaming
Stream a generated PDF directly to the browser for inline preview or printing:
4. PDF Chunking & Large Dataset Processing (pdfChunk)
When exporting large datasets (e.g. 5,000 to 50,000+ records), rendering everything in a single mPDF memory buffer can trigger memory limit crashes or mPDF backtrack errors. Reportify solves this with PDF Chunking & Merging:
In Controllers via HasReportify:
Simply pass ?export=pdfChunk in request parameters:
How PDF Chunking Works:
- Splits records into batches based on
config('reportify.chunk_size', 2000). - Generates standalone PDF parts in temporary storage without memory overflow.
- Merges all chunked PDF parts into a single output PDF using mPDF's page template importer.
- Automatically cleans up temporary chunk files from storage.
- Stamps the footer (page numbers, print date, "printed by") once onto the merged file, so page numbering runs across the whole document. Your own
hide*flags in$additionalDatastill apply to that final footer.
4. Direct Multi-Format Exports
Export directly using the Reportify Facade or reportify() global helper:
5. Listen to Export Events (Building a Download Manager)
Reportify dispatches native Laravel events during the export processing lifecycle (ExportStarted, ExportCompleted, ExportFailed). You can listen to these events in AppServiceProvider.php to track job statuses and build a Download Manager:
Then create a DownloadController to serve the generated files:
6. Add Export Buttons & Scripts to Blade Layouts
Include drop-in action buttons in your views:
Include <x-reportify-scripts /> in your master layout template (layouts/app.blade.php) for automatic query parameter preservation:
โ๏ธ Configuration Reference (config/reportify.php)
๐ $additionalData Reference
All export methods accept an $additionalData array for per-report customisation. The most commonly used keys:
| Key | Type | Description |
|---|---|---|
filename |
string |
Custom output filename (without extension) |
export_id |
string |
Unique tracking UUID for the export job (auto-generated if omitted) |
file_dir |
string |
Override the output directory |
orientation |
string |
PDF orientation: 'P' (portrait) or 'L' (landscape) |
paper_size |
string |
mPDF paper size, e.g. 'A4', 'A3', 'Letter' |
headerHtml |
string |
Raw HTML string injected into the PDF header |
headerMargin |
int |
Hard override for the PDF top margin in mm โ skips auto-calculation entirely |
additionalHeaderMargin |
int |
Additive nudge added on top of the auto-calculated (or overridden) margin. Accepts negative values |
hidePdfHeader |
bool |
Hide the PDF header entirely |
hidePdfFooter |
bool |
Hide the PDF footer entirely |
hidePageNumber |
bool |
Hide page number in footer |
hidePrintDate |
bool |
Hide print date in footer |
hidePrintBy |
bool |
Hide "printed by" user stamp in footer |
hidePoweredBy |
bool |
Hide "Powered by Reportify" line in footer |
hideVersionNumber |
bool |
Hide version number in footer |
additionalFooter |
string |
Extra HTML appended to the PDF footer |
separator |
string |
Column delimiter for TXT exports (default: \|). A heading line from the row keys is always written first |
extension |
string |
File extension for TXT exports (default: txt). Use 'none' for no extension |
no_data_exception_disabled |
bool |
Allow export to proceed with an empty dataset instead of throwing |
data_chunk_size |
int |
Override chunk size for this export only |
Header Margin Priority
For PDF exports the top margin is resolved in this order:
Examples:
๐ API Controller Support
HasReportify::exportReport() automatically detects whether the request expects JSON and returns the appropriate response โ no extra configuration needed:
Override reportifyExportResponse() in your controller for fully custom behaviour:
๐ข Multi-Tenancy Support
Reportify works seamlessly with multi-tenant Laravel packages including stancl/tenancy and spatie/laravel-multitenancy. Because ProcessReportJob implements Laravel's standard ShouldQueue interface and avoids storing Eloquent models in its constructor, tenant contexts are automatically preserved across queued export workers without serialization errors.
stancl/tenancy
When using stancl/tenancy, background exports are automatically tenant-aware via the QueueTenancyBootstrapper:
- Context Preservation: The current
tenant_idis captured on dispatch and restored beforehandle()executes. -
Database Queues: Ensure your
jobstable uses a central database connection: -
Storage Isolation: If
FilesystemTenancyBootstrapperis enabled, disks are automatically scoped. Alternatively, isolate paths using$additionalData['file_dir']: - Event Listeners: If your
downloadstable is in the central database, wrap event listeners intenancy()->central():
spatie/laravel-multitenancy
spatie/laravel-multitenancy works out of the box when queue tenant awareness is enabled in config/multitenancy.php:
- When enabled, Spatie captures the current tenant on dispatch and calls
$tenant->makeCurrent()before job execution. - If automatic awareness is disabled, pass the tenant ID via
$additionalDataand call$tenant->makeCurrent()insidegetExportData(). - Scope export directories per tenant using
$additionalData['file_dir']:
Comparison Matrix
| Feature | stancl/tenancy |
spatie/laravel-multitenancy |
|---|---|---|
| Queue Tenant Awareness | Automatic via QueueTenancyBootstrapper |
Automatic when queues_are_tenant_aware_by_default => true |
| Model Serialization Risk | None (ProcessReportJob uses scalar IDs) |
None (ProcessReportJob uses scalar IDs) |
| Storage Scoping | Built-in via filesystem bootstrapper | Handled via $additionalData['file_dir'] |
๐งช Testing
Run the test suite using Pest PHP:
53 tests, 94 assertions.
๐ค Contributing
Contributions are welcome! Please review CONTRIBUTING.md for details on code style, testing standards, and the pull request submission process.
๐ณ Credits
- Special thanks to S M Iftakhairul for architecture & design inspiration.
๐ License
The MIT License (MIT). See LICENSE.md for details.
All versions of laravel-reportify with dependencies
laravel/framework Version ^9.0|^10.0|^11.0|^12.0|^13.0
mpdf/mpdf Version ^8.0
maatwebsite/excel Version ^3.1|^4.0