Download the PHP package osama-98/laravel-exports without Composer
On this page you can find all versions of the php package osama-98/laravel-exports. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download osama-98/laravel-exports
More information about osama-98/laravel-exports
Files in osama-98/laravel-exports
Package laravel-exports
Short Description A Laravel package for exporting data in batches and chunks with support for CSV and XLSX formats
License MIT
Homepage https://github.com/osama-98/laravel-exports
Informations about the package laravel-exports
Laravel Exports
A powerful Laravel package for exporting large datasets in batches and chunks with support for CSV and XLSX formats. This package provides a clean, fluent API for handling exports efficiently.
Features
- ✅ Batch & Chunk Processing - Handle large datasets efficiently with configurable chunk sizes
- ✅ Queue-Based Exports - Process exports asynchronously using Laravel queues
- ✅ Multiple Formats - Export to both CSV and XLSX formats
- ✅ Column Mapping - Customize column names and labels
- ✅ Progress Tracking - Monitor export progress with detailed status information
- ✅ Query Builder Support - Works with both Eloquent Builder and Query Builder
- ✅ Fluent API - Laravel-style fluent interface for easy configuration
- ✅ Relationship Support - Export related model data with aggregations
- ✅ Custom Formatting - Format dates, numbers, and custom values
- ✅ Storage Flexibility - Support for local, S3, and custom storage disks
- ✅ Event System - Listen to export completion events
Requirements
- PHP 8.1 or higher
- Laravel 10.0, 11.0, or 12.0
- Queue driver configured (database, redis, sqs, etc.)
Installation
Install the package via Composer:
Publish and run the migrations:
Note: The job_batches table is required for queue batching functionality. If you're using the database queue driver, you'll also need the jobs and failed_jobs tables:
The package will automatically register its service provider.
Quick Start
1. Create an Exporter
Create an exporter class that extends Osama\LaravelExports\Exports\Exporter:
2. Start an Export
Using the Facade
Using Dependency Injection
3. Check Export Status
4. Download Export File
Usage Examples
Export with Custom Column Mapping
Export with Query Modification
Export Specific Records by IDs
Export with Max Rows Limit
Export with Custom Options
Export Using Query Builder
Export to S3
Advanced Features
Custom Column State
Customize how column values are extracted:
Column Formatting
Format dates, numbers, and add prefixes/suffixes:
Relationship Aggregations
Export aggregated data from relationships:
Query Modification in Exporter
Modify queries directly in your exporter class:
XLSX Styling
Customize XLSX cell styles:
Events
ExportCompleted Event
The ExportCompleted event is dispatched when an export finishes processing. Listen to this event to send notifications or perform post-export actions.
Example Listener:
Example Listener Class:
Register it in EventServiceProvider:
Queue Configuration
The package uses Laravel's queue batching system for processing exports. Make sure your queue is properly configured.
Required Database Tables
If you're using the database queue driver, you need the following tables:
job_batches- Required for batch processing (used by this package)jobs- Required for queue jobsfailed_jobs- Required for failed job tracking
Create these tables:
Configure Queue Driver
Configure queue in .env:
Run queue worker:
For production, use a process manager like Supervisor to keep the queue worker running.
API Reference
ExportManager Methods
| Method | Description | Example |
|---|---|---|
exporter(string $exporter) |
Set the exporter class | ->exporter(UserExporter::class) |
start(Builder\|QueryBuilder\|null $query, ?array $records, ?array $columnMap, $creator) |
Start the export | ->start(User::query(), creator: auth()->user()) |
chunkSize(int $size) |
Set chunk size (default: 100) | ->chunkSize(500) |
maxRows(?int $rows) |
Set maximum rows limit | ->maxRows(10000) |
formats(array $formats) |
Set export formats | ->formats([ExportFormat::Csv, ExportFormat::Xlsx]) |
fileDisk(?string $disk) |
Set storage disk | ->fileDisk('s3') |
fileName(?string $name) |
Set custom file name | ->fileName('my-export') |
modifyQueryUsing(?Closure $callback) |
Modify query before export | ->modifyQueryUsing(fn($q) => $q->where('active', true)) |
options(array $options) |
Set export options | ->options(['date_format' => 'Y-m-d']) |
ExportColumn Methods
| Method | Description | Example |
|---|---|---|
make(string $name) |
Create a new column | ExportColumn::make('name') |
label(string $label) |
Set column label | ->label('Full Name') |
getStateUsing(Closure\|string $callback) |
Custom state extraction | ->getStateUsing(fn($r) => $r->name) |
formatStateUsing(Closure $callback) |
Format the state value | ->formatStateUsing(fn($s) => ucfirst($s)) |
enabled(bool $enabled) |
Enable/disable by default | ->enabled(false) |
default($value) |
Set default value | ->default('N/A') |
prefix(string $prefix) |
Add prefix to value | ->prefix('$') |
suffix(string $suffix) |
Add suffix to value | ->suffix(' USD') |
limit(int $limit) |
Limit text length | ->limit(100) |
counts(string $relationship) |
Count relationship records | ->counts('orders') |
sum(string $relationship, string $column) |
Sum relationship column | ->sum('orders', 'amount') |
avg(string $relationship, string $column) |
Average relationship column | ->avg('orders', 'amount') |
Export Model Properties
| Property | Type | Description |
|---|---|---|
id |
int | Export ID |
exporter |
string | Exporter class name |
status |
ExportStatus | Export status (Pending, Processing, Completed, Failed) |
total_rows |
int | Total number of rows to export |
processed_rows |
int | Number of rows processed |
successful_rows |
int | Number of rows successfully exported |
file_name |
string | Export file name |
file_disk |
string | Storage disk name |
completed_at |
Carbon|null | Completion timestamp |
creator |
Model|null | User who created the export (morphTo) |
Export Model Methods
| Method | Description | Example |
|---|---|---|
download(string $format) |
Download export file | $export->download('xlsx') |
getFileDirectory() |
Get file directory path | $export->getFileDirectory() |
getFileDisk() |
Get Filesystem instance | $export->getFileDisk() |
getFailedRowsCount() |
Get count of failed rows | $export->getFailedRowsCount() |
progressPercentage() |
Get progress percentage (0-100) | $export->progressPercentage() |
Testing
Run the test suite:
Run tests with coverage:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This package is open-sourced software licensed under the MIT license.
Support
For issues, questions, or contributions, please visit the GitHub repository.
Credits
Developed with ❤️ for the Laravel community.
All versions of laravel-exports with dependencies
anourvalar/eloquent-serialize Version ^1.2
illuminate/contracts Version ^10.0||^11.0||^12.0
league/csv Version ^9.27
openspout/openspout Version ^5.0