
Fermin Perdomo
Full Stack Developer
Introducing laravel-model-export: Effortless Model Exporting for Laravel
Working with Laravel often means interacting with rich Eloquent models — but what happens when you need to export that data? Whether it's for auditing, backup, data sharing, or reporting, creating export logic from scratch can become repetitive and messy.
That's why we built laravel-model-export — a lightweight, elegant package that lets you export Eloquent models directly to JSON or PDF using a fluent and extensible API
✨ Features
✅ Export any Eloquent model or query
📝 JSON and PDF support (more coming soon!)
🧱 Customize columns and transformations
🔁 Supports lazy loading for huge datasets
⚡ Clean and expressive syntax
Getting Started
1. Install via Composer:
composer require php-dominicana/laravel-model-export
2. Publish the config (optional):
php artisan vendor:publish --tag=model-export-config
🧠 Basic Usage
Want to export users to JSON?
use PHPDominicana\ModelExport\Facades\ModelExport;
ModelExport::from(User::query()) ->only(['id', 'name', 'email']) ->exportToJson('users.json');
Or export to Excel?
return ModelExport::from(User::query()) ->only(['name', 'email']) ->exportToExcel('users.pdf');
Done. 🎯
💡 Advanced Example
You can also transform fields on the fly:
ModelExport::from(User::query()) ->only(['id', 'name', 'created_at']) ->transform('created_at', fn($value) => $value->format('Y-m-d')) ->exportToExcel();
And yes — the package supports streamed responses for large datasets via Laravel’s lazy()
and chunk()
behind the scenes.
🛠 Under the Hood
The export process is powered by Laravel’s native features like:
StreamedResponse
for low-memory JSON exportSupport for query builders, model collections, or raw arrays
📁 Use Cases
Exporting admin data from dashboards
Downloading reports for users
Building API endpoints for CSV/JSON data
Complying with user data portability (GDPR-style)
🤝 Contribute
We’re actively improving this package! Want to add support for:
PDF?
Remote storage (e.g. S3)?
More layout control for PDFs?
Join us on GitHub:
👉 github.com/PHP-Dominicana/laravel-model-export
👋 Final Thoughts
laravel-model-export
was built to remove the friction around exporting data in Laravel. Whether you’re building a dashboard, reporting tool, or admin panel, this package gives you an expressive and clean way to get data out of your models — without writing boilerplate.