Download the PHP package samuelterra22/laravel-report-generator without Composer
On this page you can find all versions of the php package samuelterra22/laravel-report-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download samuelterra22/laravel-report-generator
More information about samuelterra22/laravel-report-generator
Files in samuelterra22/laravel-report-generator
Package laravel-report-generator
Short Description Rapidly Generate Simple Pdf, Excel & CSV Reports on Laravel (Using Barryvdh/DomPdf or Barryvdh/laravel-snappy & maatwebsite/excel)
License MIT
Homepage https://github.com/samuelterra22/laravel-report-generator
Informations about the package laravel-report-generator
Laravel Report Generator
Generate PDF, Excel & CSV reports from Eloquent queries with a fluent API.
Zero boilerplate. Full control. Works with Laravel 10, 11 & 12.
Laravel Report Generator is a package that lets you build PDF, Excel (XLSX), and CSV reports directly from Eloquent queries or query builders using a clean, chainable API. Define columns, format values, group rows, add totals, customize styling -- all without writing HTML tables or spreadsheet logic by hand.
Key features:
- Three output formats -- PDF, Excel (XLSX), and CSV from the same fluent interface
- Multi-format export -- Define a report once, export to PDF, Excel, or CSV via
ReportExporter - Column formatting -- Transform displayed values with callbacks (
displayAs) or built-in formatters (currency, date, percentage, etc.) - Row grouping -- Group rows by one or more columns with automatic subtotals
- Advanced aggregations --
sum,avg,min,max, andcountin total rows - Conditional formatting -- Declarative rules to style cells based on data values
- Report events/hooks -- Lifecycle callbacks (
onBeforeRender,onRow,onAfterRender,onComplete) - Custom headers & footers -- Configurable content with placeholders (
{page},{date},{title}) - Report caching -- Cache rendered output with TTL and custom keys
- Custom CSS -- Inject custom styles into PDF and Excel reports
- Memory efficient -- Uses cursor-based iteration for large datasets
- Customizable templates -- Publish and modify Blade templates to fit your design
- PDF engine flexibility -- Works with either Snappy (wkhtmltopdf) or DomPDF
Table of Contents
- Requirements
- Installation
- Quick Start
- Output Examples
- Usage
- PDF Reports
- Excel Reports
- CSV Reports
- API Reference
- Initializing a Report
- Column Formatting
- Built-in Column Formatters
- Grouping & Totals
- Conditional Formatting
- Report Events / Hooks
- Custom Headers & Footers
- Multi-Format Export
- Report Caching
- Layout & Styling
- Performance
- Output Methods
- Configuration
- Customizing Templates
- Testing
- Changelog
- Contributing
- Credits
- License
Requirements
| PHP | Laravel |
|---|---|
| 8.2+ | 10.x |
| 8.2+ | 11.x |
| 8.2+ | 12.x |
Installation
Install the package via Composer:
The service provider and facades are auto-discovered -- no manual registration needed.
PDF engine (pick one)
To generate PDF reports, install one of the supported PDF engines:
If both are installed, Snappy is used by default with an automatic fallback to DomPDF.
CSV support (optional)
Quick Start
This generates a paginated PDF report with rows grouped by city, formatted currency values, and automatic totals per group.
Output Examples
Report with Grand Total
A report using showTotal() to display an automatic sum at the bottom:
Report with Group By
A report using groupBy() combined with showTotal() -- rows are grouped by date, with subtotals after each group and a final grand total:
Usage
PDF Reports
Output methods for PDF:
| Method | Description |
|---|---|
make() |
Returns the PDF object (for further manipulation) |
stream() |
Displays the PDF inline in the browser |
download($filename) |
Forces a file download (.pdf extension added automatically) |
Excel Reports
Simple version (direct sheet manipulation, better for large datasets):
Output methods for Excel:
| Method | Description |
|---|---|
make() |
Returns the Excel object for further manipulation |
download($filename) |
Exports and downloads the XLSX file |
simpleDownload($filename) |
Forces simple mode and downloads |
CSV Reports
Requires
league/csv. The.csvextension is added automatically.
Output methods for CSV:
| Method | Description |
|---|---|
download($filename) |
Outputs the CSV file for download |
API Reference
Initializing a Report
| Parameter | Type | Description |
|---|---|---|
$title |
string |
Report title displayed in the header |
$meta |
array |
Key-value pairs shown below the title (e.g., date range, filters) |
$query |
Builder\|EloquentBuilder |
The query to iterate over |
$columns |
array |
Column mapping: ['Display Name' => 'db_column'] |
Column mapping supports two formats:
Column Formatting
editColumn(string $columnName, array $options)
Customize how a column is displayed:
| Option | Type | Description |
|---|---|---|
class |
string |
CSS class applied to the column cells (left, right, bold) |
displayAs |
Closure\|string |
Callback receiving the full row, or a static string value |
editColumns(array $columnNames, array $options)
Apply the same formatting to multiple columns at once:
Built-in Column Formatters
Use formatColumn() for common formatting without writing closures. If a column has both editColumn with displayAs and formatColumn, the displayAs callback takes priority.
formatColumn(string $columnName, string $type, array $options = [])
formatColumns(array $columnNames, string $type, array $options = [])
Apply the same formatter to multiple columns:
Available format types:
| Type | Options | Default output |
|---|---|---|
currency |
prefix ($), decimals (2), decimal_separator (.), thousands_separator (,) |
$ 1,234.56 |
number |
decimals (0), decimal_separator (.), thousands_separator (,) |
1,235 |
date |
format (Y-m-d) |
2025-01-15 |
datetime |
format (Y-m-d H:i:s) |
2025-01-15 14:30:00 |
percentage |
decimals (1), suffix (%) |
75.0% |
boolean |
true (Yes), false (No) |
Yes / No |
Grouping & Totals
groupBy(string|array $column)
Group rows by one or more columns. When the group value changes, a subtotal row is inserted:
showTotal(array $columns)
Display totals for numeric columns. Each entry maps a column name to a display type:
| Type | Output format |
|---|---|
'point' |
1,234.56 (number only) |
| Any string | PREFIX 1,234.56 (uppercased prefix + number) |
Advanced aggregation types -- beyond sum, you can use:
| Aggregation | Description |
|---|---|
sum |
Sum of all values (default for unknown types) |
avg |
Arithmetic mean |
min |
Minimum value |
max |
Maximum value |
count |
Number of rows |
point |
Same as sum, but displayed without a label prefix |
Conditional Formatting
Apply CSS styles to cells based on their values. In PDF/Excel reports the styles are applied as inline CSS. CSV reports ignore formatting gracefully.
conditionalFormat(string $columnName, callable $condition, array $styles)
The condition callback receives ($cellValue, $rowObject), so you can also style based on other columns:
Report Events / Hooks
Register callbacks that fire at specific points in the report lifecycle. Useful for logging, progress tracking, auditing, and post-processing.
Multiple callbacks can be registered for the same event -- they fire in registration order.
Custom Headers & Footers
Customize the header and footer content of PDF reports. Supports positional placement and placeholders.
setHeaderContent(string $content, string $position = 'center')
setFooterContent(string $content, string $position = 'center')
clearHeader() / clearFooter()
Remove all header or footer content:
Available placeholders:
| Placeholder | Description |
|---|---|
{page} |
Current page number |
{pages} |
Total page count |
{date} |
Current date (Y-m-d) |
{title} |
Report title |
Defaults:
Multi-Format Export
Define a report once and export to multiple formats without duplicating configuration. Use ReportExporter to build the report, then call toPdf(), toExcel(), or toCsv().
ReportExporter supports all the same fluent methods as the individual report classes (editColumn, formatColumn, groupBy, showTotal, conditionalFormat, cacheFor, etc.).
Report Caching
Cache the rendered report output to avoid re-rendering on repeated requests. Cached HTML is stored via Laravel's cache system.
cacheFor(int $minutes)
Enable caching with a TTL in minutes:
cacheAs(string $key)
Set a custom cache key (otherwise an auto-generated key based on title, columns, meta, limit, and groupBy is used):
cacheUsing(string $store)
Use a specific cache store (e.g., redis, file, array):
noCache()
Explicitly disable caching (useful to override a previously set cacheFor):
On cache hit, the template rendering step is skipped entirely and the cached HTML is loaded directly into the PDF/CSV engine.
Layout & Styling
setPaper(string $size) (PDF only)
Set the paper size. Default: a4.
setOrientation(string $orientation) (PDF only)
Set page orientation. Default: portrait.
setCss(array $styles) (PDF & Excel)
Inject custom CSS rules into the report template:
showHeader(bool $value = true)
Show or hide the column header row. Default: true.
showMeta(bool $value = true)
Show or hide the meta information section. Default: true (except CSV, which defaults to false).
showNumColumn(bool $value = true)
Show or hide the auto-incrementing row number column (No). Default: true.
Performance
limit(int $n)
Limit the number of rows processed:
withoutManipulation()
Skip column editing logic entirely for faster generation. Uses a simpler template that renders raw column values:
simple() (Excel only)
Use direct sheet manipulation instead of Blade template rendering. Better for large datasets:
Configuration
Publish the config file:
This creates config/report-generator.php:
Customizing Templates
Publish the Blade templates to customize the report layout:
This publishes four templates to resources/views/vendor/laravel-report-generator/:
| Template | Used by |
|---|---|
general-pdf-template.blade.php |
PDF reports with column manipulation |
general-excel-template.blade.php |
Excel reports with column manipulation |
without-manipulation-pdf-template.blade.php |
PDF reports using withoutManipulation() |
without-manipulation-excel-template.blade.php |
Excel reports using withoutManipulation() |
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Credits
- Samuel Terra
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-report-generator with dependencies
illuminate/support Version ^10.0||^11.0||^12.0
maatwebsite/excel Version ^3.1
spatie/laravel-package-tools Version ^1.16