php-dominicana/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.
User::where(...)->exportToExcel())lazyById()composer require php-dominicana/laravel-model-export
Export all records (static call)
User::exportToExcel(); // uses default filename and $exportable columns
User::where('active', true)
->orderBy('name')
->exportToExcel(); // exports only active users
User::exportToExcel(storage_path('exports/users.csv'));
Files are exported to /storage/app by default unless a custom path is provided.
Filenames follow this format: export_ModelName_TIMESTAMP.csv
User::streamDownload();
User::exportToJson();
User::exportToPDF();
To let users override your default PDF view, instruct them to publish it:
php artisan vendor:publish --tag=model-export-views
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().
How can I help you explore Laravel packages today?