Download the PHP package phpmystic/eloquent-exporter without Composer
On this page you can find all versions of the php package phpmystic/eloquent-exporter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package eloquent-exporter
Eloquent Exporter
Export Eloquent models to CSV & Excel with a fluent API. Supports relationships, custom headers, formatting, chunking, and multi-sheet Excel files.
Requirements
- PHP 8.0+
- Laravel 9, 10, 11, or 12
Installation
The service provider is auto-discovered by Laravel.
Basic Usage
From a Query
Custom Headers
Relationships
Relations are eager-loaded automatically to prevent N+1 queries.
BelongsTo / HasOne (Dot Notation)
| Name | Department | Manager | |
|---|---|---|---|
| John | [email protected] | Engineering | Jane |
| Sara | [email protected] | Marketing | Bob |
HasMany (Comma-Separated)
HasMany relationships are joined into a single cell by default.
| Name | Roles |
|---|---|
| John | Admin, Editor |
| Sara | Viewer |
Use a custom separator:
Expand Rows
Flatten HasMany relationships so each related record becomes its own row.
| Order # | Customer | Product | Qty | Price |
|---|---|---|---|---|
| 1001 | John | Keyboard | 1 | 79.99 |
| 1001 | John | Mouse | 2 | 29.99 |
| 1002 | Sara | Monitor | 1 | 399.99 |
Nested expand is also supported:
BelongsToMany with Pivot Data
Formatting Values
Download Response
Return a download response directly from a controller. The format is auto-detected from the file extension.
Chunking
Process large datasets in chunks to reduce memory usage.
Exportable Trait
Add the Exportable trait to your model for a convenient shorthand.
Excel Sheets
Custom Sheet Name
Multiple Static Sheets
Dynamic Sheets (One Sheet per Record)
Generate a sheet for each record, with related data as rows.
This creates a sheet per user (named after name), each containing that user's posts.
Use a callback for custom sheet names:
Sheet Meta
Add parent record attributes as header rows above the data table.
Combining Static and Dynamic Sheets
API Reference
| Method | Description |
|---|---|
EloquentExporter::for(Model::class) |
Create exporter for a model class |
EloquentExporter::query($builder) |
Create exporter from a query builder |
->columns(array $columns) |
Set columns to export (supports dot notation and custom headers) |
->format(string $column, Closure $formatter) |
Apply a formatter callback to a column |
->separator(string $column, string $sep) |
Set separator for HasMany comma-joined values |
->expandRows(string $relation) |
Flatten a HasMany/BelongsToMany into separate rows |
->chunk(int $size) |
Process records in chunks |
->sheetName(string $name) |
Set the Excel sheet name |
->addSheet(Builder $query, array $columns, string $name) |
Add an additional static sheet |
->sheetPerRecord(string\|Closure $key) |
Create one sheet per record |
->sheetMeta(array $columns) |
Add parent record meta rows to dynamic sheets |
->addDynamicSheets(Builder $query, Closure $name, array $columns) |
Add dynamic sheets alongside static ones |
->toCsv(string $path) |
Export to a CSV file |
->toExcel(string $path) |
Export to an Excel (.xlsx) file |
->download(string $filename) |
Return a download response (format auto-detected) |
License
MIT
All versions of eloquent-exporter with dependencies
illuminate/support Version ^9.0|^10.0|^11.0|^12.0
phpoffice/phpspreadsheet Version ^1.29|^2.0|^3.0|^4.0|^5.0