Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Model Export Laravel Package

php-dominicana/laravel-model-export

View on GitHub
Deep Wiki
Context7

laravel-model-export

A lightweight Laravel package to export Eloquent model data to CSV, excel, with support for low-memory, lazy exports and a clean API via an Exportable trait and query macro.

📦 Features

  • Export model data to CSV using a simple method call
  • Export via query chaining (User::where(...)->exportToExcel())
  • Low memory usage via lazyById()
  • Customizable export paths

🚀 Installation

composer require php-dominicana/laravel-model-export

🛠 Usage

Export all records (static call)

User::exportToExcel(); // uses default filename and $exportable columns

Export filtered data via query

User::where('active', true)
    ->orderBy('name')
    ->exportToExcel(); // exports only active users

Export to custom path

User::exportToExcel(storage_path('exports/users.csv'));

📁 File Output

  • Files are exported to /storage/app by default unless a custom path is provided.

  • Filenames follow this format: export_ModelName_TIMESTAMP.csv

Export to browser

User::streamDownload();

Export to JSON

User::exportToJson();

Export to PDF

User::exportToPDF();

Customize the PDF View (Optional)

To let users override your default PDF view, instruct them to publish it:

php artisan vendor:publish --tag=model-export-views

🧠 How It Works

  • The Exportable trait adds a static exportToExcel() method for convenience.

  • A macro is registered on Eloquent\Builder so that you can chain ->exportToExcel() on queries.

  • Under the hood, Spatie’s SimpleExcelWriter handles the CSV generation.

  • Memory-efficient thanks to Laravel’s lazyById().

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle
glavweb/api-bundle
glavweb/admin-bundle
adachsoft/api-version-bundle
elsayed85/laravel-api-exceptions
ouhssini/laravel-demo-mode
daworks/ncloud-outbound-mailer-driver
gp247/cms
ignibyte/aic-gates
nexa-merchant/blog
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
cgv/localized-resource