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 syntaxGetting Started1. 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?
User::exportToJson();
export to Excel?
User::exportToExcel(); // uses default filename and $exportable columns
Export to PDF
User::exportToPDF();
✅ Done.
💡 Advanced Example
yes — the package supports streamed responses for large datasets using Laravel’s lazy() and chunk() methods behind the scenes.
🛠 Under the Hood
The export process is powered by Laravel’s native features like:
- StreamedResponse for low-memory JSON export
- Support 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:
- ☁️ 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.
Please login to leave a comment.