Introducing laravel-model-export: Effortless Model Exporting for Laravel

Fermin Perdomo Fermin Perdomo
schedule 2 min read

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.


Reactions

lock You need to be logged in to react.
Log In

Newsletter

Get new posts delivered straight to your inbox.

mail

Great Tools for Developers

Git Tower

Git Tower

A powerful Git client for Mac and Windows that simplifies version control.

Visit arrow_forward
Mailcoach

Mailcoach

Self-hosted email marketing platform for sending newsletters and automated emails.

Visit arrow_forward
Uptimia

Uptimia

Website monitoring and performance testing tool to ensure your site is always up and running.

Visit arrow_forward
Cloudways

Cloudways

Managed cloud hosting platform that simplifies server management for developers.

Visit arrow_forward

Comments

No comments yet. Be the first to share your thoughts.

chat_bubble Join the conversation — log in to leave a comment.
Log In