PHPackages                             fersot/model-export - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. fersot/model-export

ActiveLibrary[Database &amp; ORM](/categories/database)

fersot/model-export
===================

Export Eloquent queries, collections or arrays to Excel/CSV with a fluent API, column mapping, chunk processing and streaming downloads.

v1.0.0(3mo ago)00MITPHPPHP ^8.1

Since Mar 26Pushed 3mo agoCompare

[ Source](https://github.com/fersot/model-export)[ Packagist](https://packagist.org/packages/fersot/model-export)[ Docs](https://github.com/fersot/model-export)[ RSS](/packages/fersot-model-export/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (6)Versions (2)Used By (0)

Laravel Model Export
====================

[](#laravel-model-export)

Export **Eloquent queries**, **Collections**, or **arrays** to Excel or CSV with a fluent API, column mapping, transform callbacks, chunk processing, and streaming HTTP downloads.

[![Latest Version](https://camo.githubusercontent.com/3eb07d2870c045b7bcafad5792704aacc897fa7253d2e68ec1f9020b3c9b6a95/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666572736f742f6d6f64656c2d6578706f72742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/fersot/model-export)[![PHP Version](https://camo.githubusercontent.com/ee631d1b3535e8b3a99c9152d465e9db0c74b77d6c84694515f8ebc38cda9aea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c75653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/fersot/model-export)[![License](https://camo.githubusercontent.com/422db9fd40f5831c765cf6530b6750c081b696bd18d904cf89554df98c676277/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e3f7374796c653d666c61742d737175617265)](LICENSE)[![Tests](https://camo.githubusercontent.com/a66fa9aef1f69625fc9ed5c2ef94bfc94fad3921c789dcbc1c0b91b2a10d109f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d323225323070617373696e672d627269676874677265656e3f7374796c653d666c61742d737175617265)](#)

Installation
------------

[](#installation)

```
composer require fersot/model-export
```

Laravel auto-discovers the service provider and facade. Optionally publish the config:

```
php artisan vendor:publish --tag=model-export-config
```

---

Quick Start
-----------

[](#quick-start)

```
use Fersot\ModelExport\Exporter;

// Download directly from a controller
return Exporter::from(User::query())->download('users.xlsx');

// Save to disk
Exporter::from(Order::where('status', 'paid'))->toExcel(storage_path('exports/orders.xlsx'));

// With column mapping
return Exporter::from(User::query())
    ->columns([
        ExportColumn::make('name')->label('Nombre'),
        ExportColumn::make('email')->label('Correo'),
        ExportColumn::make('created_at')->label('Registro')->transform(fn($v) => $v->format('d/m/Y')),
    ])
    ->download('usuarios.xlsx');
```

---

Sources
-------

[](#sources)

```
use Fersot\ModelExport\Exporter;

// Eloquent Builder
Exporter::from(User::where('active', 1));

// Illuminate Collection
Exporter::from(collect([['name' => 'Alice'], ['name' => 'Bob']]));

// Plain PHP array
Exporter::from([['product' => 'Widget', 'price' => 9.99]]);

// Model shortcut (uses Model::query())
Exporter::model(User::class);
```

---

Fluent Options
--------------

[](#fluent-options)

### Column Mapping

[](#column-mapping)

Define columns explicitly with a custom label and optional value transformer:

```
use Fersot\ModelExport\ExportColumn;

Exporter::from(User::query())
    ->columns([
        ExportColumn::make('name')->label('Nombre'),
        ExportColumn::make('email')->label('Correo Electrónico'),
        ExportColumn::make('age')->label('Edad')->transform(fn($v) => "{$v} años"),

        // The transform also receives the full row as a second argument
        ExportColumn::make('name')->label('Info')
            ->transform(fn($v, $row) => "{$v} "),
    ])
    ->download('users.xlsx');
```

When `->columns()` is used, **only** the specified columns are exported in the exact order defined.

### Filter Columns (without mapping)

[](#filter-columns-without-mapping)

```
// Keep only these columns
Exporter::from(User::query())->only(['name', 'email'])->toArray();

// Exclude columns
Exporter::from(User::query())->except(['password', 'remember_token'])->toArray();
```

### Chunk Processing (large datasets)

[](#chunk-processing-large-datasets)

```
Exporter::from(User::query())
    ->chunk(500)           // default: 1000
    ->download('all_users.xlsx');
```

---

Output Formats
--------------

[](#output-formats)

```
$exporter = Exporter::from(User::query());

// PHP array / Collection
$exporter->toArray();
$exporter->toCollection();

// Save to file
$exporter->toExcel('path/to/output.xlsx');   // returns the path
$exporter->toCsv('path/to/output.csv');      // returns the path

// HTTP download (StreamedResponse)
$exporter->download('filename.xlsx');
$exporter->downloadCsv('filename.csv');
```

---

Macros
------

[](#macros)

After the service provider boots, macros are available on `EloquentBuilder` and `Collection`:

```
// Builder macros
User::where('active', 1)->toExcel(storage_path('exports/active_users.xlsx'));
User::where('active', 1)->toCsv(storage_path('exports/active_users.csv'));

// Return a download response directly
return User::query()->exportDownload('users.xlsx');
return User::query()->exportDownloadCsv('users.csv');

// Collection macros
$collection->toExcel('path/to/file.xlsx');
return $collection->exportDownload('data.xlsx');
```

---

HasExport Trait
---------------

[](#hasexport-trait)

Add the trait to any Eloquent model for convenient export methods:

```
use Fersot\ModelExport\Traits\HasExport;

class User extends Model
{
    use HasExport;
}

// Export all records
return User::export()->only(['name', 'email'])->download('users.xlsx');

// Export with a scoped query
return User::exportQuery(fn($q) => $q->where('role', 'admin'))
    ->download('admins.xlsx');
```

---

Configuration
-------------

[](#configuration)

After publishing, edit `config/model-export.php`:

```
return [
    'chunk_size'     => 1000,
    'disk'           => 'local',
    'default_format' => 'xlsx',
    'temp_path'      => null,   // null = sys_get_temp_dir()
];
```

---

Requirements
------------

[](#requirements)

DependencyVersionPHP`^8.1`Laravel`^9.0 | ^10.0 | ^11.0 | ^12.0`fersot/excel-to`^2.0`---

Testing
-------

[](#testing)

```
composer install
./vendor/bin/phpunit --testdox
```

22 tests covering all features.

---

Author
------

[](#author)

**Hember Colmenares** —  · [GitHub](https://github.com/fersot)

Support ☕️
----------

[](#support-️)

[![Buy Me a Coffee](https://camo.githubusercontent.com/48e263a7a2c3a0618ed500a63b90f03fc7338cd104f35711fb6506f783c63007/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4275792532304d6525323061253230436f666665652d4646383133463f7374796c653d666f722d7468652d6261646765266c6f676f3d6275796d6561636f66666565266c6f676f436f6c6f723d7768697465)](https://buymeacoffee.com/fersot)

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance82

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

91d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/11588218?v=4)[Hember Colmenares](/maintainers/fersot)[@fersot](https://github.com/fersot)

---

Top Contributors

[![fersot](https://avatars.githubusercontent.com/u/11588218?v=4)](https://github.com/fersot "fersot (1 commits)")

---

Tags

laravelexporteloquentexcelcsvcollectionphpspreadsheetdownload

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/fersot-model-export/health.svg)

```
[![Health](https://phpackages.com/badges/fersot-model-export/health.svg)](https://phpackages.com/packages/fersot-model-export)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k51.0M7.6k](/packages/larastan-larastan)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[api-platform/laravel

API Platform support for Laravel

59156.3k11](/packages/api-platform-laravel)[ntanduy/cloudflare-d1-database

Cloudflare D1 database driver for Laravel — full Eloquent &amp; Query Builder support.

276.8k](/packages/ntanduy-cloudflare-d1-database)[calebdw/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

15104.9k4](/packages/calebdw-larastan)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
