- How do I export an Eloquent model to Excel in Laravel using this package?
- Use the `FromModel` class to export Eloquent models. For example, `Excel::download(new UsersExport, 'users.xlsx')` where `UsersExport` extends `FromModel`. The package automatically handles chunking for large datasets and respects Laravel’s Eloquent conventions.
- Does Laravel Excel support CSV imports with validation?
- Yes, you can validate CSV imports using Laravel’s built-in validation rules. Extend `FromCollection` or `FromArray` and use the `WithValidation` concern to apply rules like `required`, `email`, or custom validation logic before saving data.
- Can I queue large Excel exports to avoid timeouts in Laravel?
- Absolutely. Use the `queue` method in your export class (e.g., `Excel::queue(new LargeExport, 'large-export.xlsx')`) to process exports in the background. This is ideal for datasets exceeding 50K+ rows and integrates with Laravel’s queue system (e.g., Redis, database).
- What Laravel versions does maatwebsite/excel support?
- The package supports Laravel 5.8 through 12.x. As of version 3.1.47, Laravel 10 is officially supported. Check the [composer.json](https://github.com/SpartnerNL/Laravel-Excel/blob/3.1/composer.json) for specific version constraints and PHP 7.2–8.2 compatibility.
- How do I handle multi-sheet Excel exports with Laravel Excel?
- Extend `FromCollection` and use the `withSheets` method to define multiple sheets. For example, pass an array of sheet configurations where each key is the sheet name and the value is a collection or closure. The package merges them into a single Excel file.
- Is there a way to test Excel exports/imports in Laravel?
- Yes, use the `Excel::fake()` helper to mock exports and imports in unit tests. This allows you to assert file contents without generating actual files. The package also supports mocking storage disks for isolated testing.
- Can I style Excel cells (e.g., colors, fonts) with Laravel Excel?
- Yes, use the `WithStyles` concern to apply cell formatting. For example, set background colors, fonts, or borders directly in your export class. Under the hood, it leverages PhpSpreadsheet’s styling capabilities for full control.
- What are the alternatives to Laravel Excel for Excel handling in Laravel?
- Alternatives include `box/spout` (lightweight but less feature-rich) or `phpoffice/phpexcel` (older, less maintained). Laravel Excel stands out for its seamless Laravel integration, chunking, queuing, and active maintenance. For Nova users, `maatwebsite/nova-excel` is a dedicated extension.
- How do I handle large CSV imports without memory issues in Laravel?
- Use the `WithChunkReading` concern to process imports row-by-row instead of loading the entire file into memory. This is critical for files >10MB. Combine it with queuing for background processing to avoid timeouts in production.
- Does Laravel Excel support Excel formulas (e.g., SUM, VLOOKUP) in exported files?
- Yes, since it’s built on PhpSpreadsheet, you can add formulas to cells. Use the `setValue()` method with formula syntax (e.g., `'=SUM(B2:B10)'`) in your export class. Note that complex formulas may impact performance for very large exports.