Overview
The Export system leverages Laravel Excel (Maatwebsite) to generate professional Excel reports with custom formatting, column styling, and optimized performance. All major modules support filtered exports with consistent styling and proper data formatting.Exports automatically apply active filters, allowing users to export exactly what they see on screen.
Architecture
Exports are implemented using Laravel Excel’s concern-based architecture:Basic Export Structure
Complete Export Implementation
Initialize Cache
Load reference data (clients, statuses) into memory to avoid N+1 queries during mapping
Controller Implementation
Export with Active Filters
Route Definition
Frontend Trigger
Common Export Examples
Sales Export
Journal Entries Export
NCF Logs Export (DGII Compliance)
Payments Export
Performance Optimization
Cache Reference Data
Load all reference data once in the constructor:Eager Load Relationships
Use Chunking for Large Datasets
Queue Large Exports
Styling Patterns
Professional Color Schemes
Number Formats
Conditional Formatting
Advanced Features
Multiple Sheets
Custom Headers and Footers
Auto-Filter
Best Practices
Cache Reference Data
Cache Reference Data
Always load catalogs (clients, products, statuses) in the constructor to avoid thousands of individual queries during mapping.
Use Eager Loading
Use Eager Loading
Load all relationships needed for export in the
query() method:Format Numbers Properly
Format Numbers Properly
Use Excel number formats instead of pre-formatting in PHP:
Descriptive Filenames
Descriptive Filenames
Include date/time in export filenames:
Queue Large Exports
Queue Large Exports
For exports with >10,000 rows, implement
ShouldQueue to prevent timeouts.Troubleshooting
Memory Exhausted on Large Exports
Cause: Loading too many records at once. Solution: Implement chunking:N+1 Query Problem (Slow Exports)
Cause: Not eager loading relationships. Solution: Enable query log and check:query() method.
Currency Format Not Applied
Cause: Cell contains string instead of numeric value. Solution: Return raw numbers inmap():