maatwebsite/excel
Laravel Excel wraps PhpSpreadsheet to make fast, elegant Excel/CSV imports and exports in Laravel. Export collections or queries with automatic chunking, build multi-sheet files, and handle queued, large datasets with a simple API and solid docs.
FromModel, FromCollection, FromQuery).BeforeImport, AfterImport, BeforeExport, AfterExport) for extensibility.WithValidation, WithChunkReading, WithStyles) enable granular customization without bloating core logic.maatwebsite/excel) + minimal config (config/excel.php). No complex setup for basic use cases.Exportable, Importable traits) for familiarity.| Risk Area | Mitigation |
|---|---|
| Memory/Performance | Chunk reading (WithChunkReading) and queuing mitigate large-file issues. |
| PhpSpreadsheet | Version pinning in composer.json avoids breaking changes (e.g., PhpSpreadsheet 1.16+). |
| Deprecations | Active maintenance (Laravel 10 support as of 3.1.47). |
| Custom Logic | Concerns like WithCustomCasts or WithHeadings require PHP knowledge. |
| Testing | Mocking Excel::fake() simplifies unit tests. |
WithUpsertColumns).FromView).Excel::fake()).fputcsv, third-party tools).FromModel/FromCollection) to validate performance.| Component | Compatibility Notes |
|---|---|
| Laravel | 5.8–12.x (v3.1.x). Laravel 10 supported as of 3.1.47. |
| PHP | 7.2–8.2 (check composer.json constraints). |
| Databases | Works with any DB supported by Laravel (MySQL, PostgreSQL, etc.). |
| Storage | Uses Laravel’s filesystem (supports S3, GCS, etc.). |
| Third-Party | No hard dependencies; conflicts unlikely. |
| Legacy Code | FromArray/FromCollection can wrap existing data structures. |
composer require maatwebsite/excel
php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" --tag=config
config/excel.php (e.g., disk, chunk size).import tables (optional).artisan make:export/artisan make:import for scaffolding.Excel::fake() in unit tests.ShouldQueue).WithCustomCasts) may need maintenance if package evolves.chunkSize can cause timeouts.WithValidation requires proper Laravel validator rules.WithChunkReading) + queuing (ShouldQueue) handle millions of rows.chunkReading) reduce DB load.memory_limit.memory_get_usage() and microtime() for bottlenecks.| Scenario | Mitigation Strategy |
|---|---|
| Queue Timeouts | Increase QUEUE_TIMEOUT in .env; use retryUntil. |
| Memory Exhaustion | Reduce chunkSize; offload to disk with WithTempFiles. |
| Corrupt Imports | Validate files pre-import; use WithValidation. |
| DB Locks | Batch inserts (chunkReading); avoid transactions for large imports. |
| Storage Failures | Retry failed disk operations; monitor storage quotas. |
| PhpSpreadsheet Crashes | Downgrade PhpSpreadsheet if using unstable versions. |
How can I help you explore Laravel packages today?