hexagonlabsllc / laravel-exports
Comprehensive export feature that utilizes Laravel's model backbone to create customizable exports.
Requires
- php: ^8.2
- illuminate/bus: ^12.12||^13.0
- illuminate/console: ^12.12||^13.0
- illuminate/contracts: ^12.12||^13.0
- illuminate/database: ^12.12||^13.0
- illuminate/http: ^12.12||^13.0
- illuminate/queue: ^12.12||^13.0
- illuminate/support: ^12.12||^13.0
Requires (Dev)
- larastan/larastan: ^3.10
- laravel/pint: ^1.14
- orchestra/testbench: ^10.0.0||^11.0.0
- pestphp/pest: ^3.0||^4.0
- pestphp/pest-plugin-arch: ^3.0||^4.0
- pestphp/pest-plugin-laravel: ^3.0||^4.0
- phpoffice/phpspreadsheet: ^2.3||^3.0||^4.0||^5.0
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
Suggests
- phpoffice/phpspreadsheet: Required for xlsx exports (^2.3||^3.0||^4.0||^5.0)
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-02 22:49:58 UTC
README
A powerful, database-driven export system for Laravel applications that provides dynamic, configurable exports without writing code.
Features
- Database-Driven Configuration - Define exports through database records; a single layout row can carry its columns, filters, and sorts as JSON
- Lazy Catalog Sync - Models and relations register themselves on first reference; no setup command required
- Fluent Builder -
ExportLayoutBuildercomposes and validates complete layouts in one chain - Validation - Spot-check layouts before saving or via
php artisan export:validate, with overridable, localizable messages - Advanced Filtering - Static filters, request-based filters, smart dotted-path filters, and collection filters, with grouped or logic
- Nested Relationship Support - Export deeply nested data using dot notation
- Dynamic Column Expansion - One configured column fans out into a column per related value, titled by a
{value}template - Format Templates - Wrap cell values with templates like
Site {value} - Pivot/Crosstab Reports - Excel-style pivot exports with grouping, sub-groups, and dynamic columns
- Pivot Table Data - Access BelongsToMany pivot attributes via
.pivot.notation - Transformation Functions - 23 built-in functions for formatting dates, strings, numbers
- Aggregations - Sum, count, average, min, max, first, last on collections, including filtered subsets
- Large Dataset Support - Chunking, streaming, and background job processing
- Multiple Formats - CSV and JSON out of the box, multi-sheet XLSX via the optional phpoffice/phpspreadsheet package. Need PDF or something custom? Consume the array output from
executeExport()and render it however you like, or register your own handler viaExportFactory::register()
Documentation
Full documentation is available in the docs directory:
- Getting Started - Installation and setup
- Configuration - All configuration options, including schema sync modes
- Guides - In-depth guides for each feature
- Examples - Practical examples from basic to advanced
- API Reference - Complete class and method documentation
- Troubleshooting - Common issues and solutions
Quick Start
Installation
composer require hexagonlabsllc/laravel-exports
Setup
# Publish configuration and migrations php artisan vendor:publish --provider="HexagonLabsLLC\LaravelExports\LaravelExportsServiceProvider" # Run migrations php artisan migrate # Optional: seed the built-in transformation functions php artisan export:seed-functions
That is the whole setup. Models and their relations sync into the export catalog automatically the first time a layout references them (configurable via schema_sync; php artisan export:import-models --deep still pre-populates everything at once if you prefer).
Basic Usage
use HexagonLabsLLC\LaravelExports\Builders\ExportLayoutBuilder; use HexagonLabsLLC\LaravelExports\Services\DynamicExportService; // 1. Build a layout - paths are validated, everything saves in one transaction $layout = ExportLayoutBuilder::for(\App\Models\User::class) ->name('user_export') ->title('User Export') ->column('Name', 'name') ->column('Email', 'email') ->column('Department', 'department.name') ->save(); // 2. Export it $service = app(DynamicExportService::class); return $service->downloadAs($layout, 'csv', 'users.csv');
Layouts are plain database rows, so they can also come from anywhere else - an admin UI, a seeder, or raw SQL:
ExportLayout::create([ 'model' => \App\Models\User::class, 'name' => 'user_export', 'column_definitions' => ['Name' => 'name', 'Email' => 'email'], 'filter_definitions' => [['path' => 'active', 'operator' => '=', 'value' => true]], 'sort_definitions' => [['path' => 'name']], ]);
Validation
Spot-check a layout before saving, or audit every layout in CI:
$problems = ExportLayoutBuilder::for(User::class)->column('Name', 'name')->validate(); $problems = app(LayoutValidator::class)->validateDraft($request->all());
php artisan export:validate # exits non-zero when any layout has errors
Messages are translatable and overridable: publish the lang tag and edit lang/vendor/laravel-exports/{locale}/validation.php to give clients friendlier wording, or map each problem's code and params to your own frontend strings.
Request-Based Filtering
ExportLayout::create([ 'model' => \App\Models\User::class, 'name' => 'filtered_users', 'column_definitions' => ['Name' => 'name'], 'filter_definitions' => [ ['path' => 'status', 'operator' => '=', 'is_request' => true], ], ]); // In your controller $service->downloadAs($layout, 'csv', 'users.csv', ['status' => 'active']);
Large Datasets
// Streaming return $service->streamAs($layout, 'csv', 'large.csv', [], [], 1000); // Background job $exportId = $service->queueExport($layout, 'csv'); $status = ProcessExportJob::getStatus($exportId);
Multi-Sheet XLSX
composer require phpoffice/phpspreadsheet
return $service->downloadAs($layout, 'xlsx', 'report.xlsx', [], ['sheet_by' => 'Author']);
Requirements
- PHP 8.2+
- Laravel 12.12+ or 13
- Database with UUID support
Learn More
See the full documentation for:
- Nested Relationships - Deep data traversal
- Pivot Tables - BelongsToMany pivot data
- Pivot Reports - Crosstab reports with grouping and date buckets
- Transformation Functions - All 23 functions
- Aggregations - Collection aggregation
- Large Datasets - Performance optimization
- Background Jobs - Queue processing
License
The MIT License (MIT). Please see License File for more information.