zappzerapp / laravel-ingest
A robust, configuration-driven ETL and data import framework for Laravel. Handles CSV/Excel streaming, queues, validation, and relationships.
Fund package maintenance!
Patreon
www.buymeacoffee.com/wbbl
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/zappzerapp/laravel-ingest
Requires
- php: ^8.3
- ext-fileinfo: *
- ext-json: *
- halaxa/json-machine: ^1.2
- illuminate/contracts: ^10.0 || ^11.0 || ^12.0
- illuminate/database: ^10.0 || ^11.0 || ^12.0
- illuminate/filesystem: ^10.0 || ^11.0 || ^12.0
- illuminate/http: ^10.0 || ^11.0 || ^12.0
- illuminate/queue: ^10.0 || ^11.0 || ^12.0
- illuminate/support: ^10.0 || ^11.0 || ^12.0
- illuminate/validation: ^10.0 || ^11.0 || ^12.0
- laravel/serializable-closure: ^1.3|^2.0
- spatie/simple-excel: ^3.2
Requires (Dev)
- larastan/larastan: ^2.11
- laravel/pint: ^1.13
- league/flysystem-ftp: ^3.0
- orchestra/testbench: ^8.0 || ^9.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- roave/security-advisories: dev-latest
README
Stop writing spaghetti code for imports.
Laravel Ingest is a robust, configuration-driven ETL (Extract, Transform, Load) framework for Laravel. It replaces fragile, procedural import scripts with elegant, declarative configuration classes.
Whether you are importing 100 rows or 10 million, Laravel Ingest handles the heavy lifting: streaming, chunking, queueing, validation, relationships, and error reporting.
β‘ Why use this?
Most import implementations suffer from the same issues: memory leaks, timeouts, lack of validation, and messy controllers.
Laravel Ingest solves this by treating imports as a first-class citizen:
- βΎοΈ Infinite Scalability: Uses Generators and Queues to process files of any size with flat memory usage.
- π Declarative Syntax: Define what to import, not how to loop over it.
- π§ͺ Dry Runs: Simulate imports to find validation errors without touching the database.
- π Auto-Relations: Automatically resolves
BelongsToandBelongsToManyrelationships (e.g., finding IDs by names). - π‘οΈ Robust Error Handling: Tracks every failed row and allows you to download a CSV of only the failures to fix and retry.
- π API & CLI Ready: Comes with auto-generated API endpoints and Artisan commands.
π Documentation
Full documentation is available at zappzerapp.github.io/laravel-ingest.
π Quick Start
1. Installation
composer require zappzerapp/laravel-ingest # Publish config & migrations php artisan vendor:publish --provider="LaravelIngest\IngestServiceProvider" # Create tables php artisan migrate
2. Define an Importer
Create a class implementing IngestDefinition. This is the only code you need to write.
namespace App\Ingest; use App\Models\User; use LaravelIngest\Contracts\IngestDefinition; use LaravelIngest\IngestConfig; use LaravelIngest\Enums\SourceType; use LaravelIngest\Enums\DuplicateStrategy; class UserImporter implements IngestDefinition { public function getConfig(): IngestConfig { return IngestConfig::for(User::class) ->fromSource(SourceType::UPLOAD) ->keyedBy('email') // Identify records by email ->onDuplicate(DuplicateStrategy::UPDATE) // Update if exists // Map CSV columns to DB attributes ->map('Full Name', 'name') ->map(['E-Mail', 'Email Address'], 'email') // Supports aliases // Handle Relationships automatically ->relate('Role', 'role', Role::class, 'slug', createIfMissing: true) // Validate rows before processing ->validate([ 'email' => 'required|email', 'Full Name' => 'required|string|min:3' ]); } }
3. Register it
In App\Providers\AppServiceProvider:
use LaravelIngest\IngestServiceProvider; public function register(): void { $this->app->tag([UserImporter::class], IngestServiceProvider::INGEST_DEFINITION_TAG); }
4. Run it!
You can now trigger the import via CLI or API.
Via Artisan (Backend / Cron):
php artisan ingest:run user-importer --file=users.csv
Via API (Frontend / Upload):
curl -X POST \ -H "Authorization: Bearer <token>" \ -F "file=@users.csv" \ https://your-app.com/api/v1/ingest/upload/user-importer
π Features in Depth
Monitoring & Management
Ingest runs happen in the background. You can monitor and manage them easily:
| Command | Description |
|---|---|
ingest:list |
Show all registered importers. |
ingest:status {id} |
Show progress bar, stats, and errors for a run. |
ingest:cancel {id} |
Stop a running import gracefully. |
ingest:retry {id} |
Create a new run containing only the rows that failed previously. |
API Endpoints
The package automatically exposes endpoints for building UI integrations (e.g., React/Vue progress bars).
GET /api/v1/ingest- List recent runs.GET /api/v1/ingest/{id}- Get status and progress.GET /api/v1/ingest/{id}/errors/summary- Get aggregated error stats (e.g., "50x Email invalid").GET /api/v1/ingest/{id}/failed-rows/download- Download a CSV of failed rows to fix & re-upload.
Events
Hook into the lifecycle to send notifications (e.g., Slack) or trigger downstream logic.
LaravelIngest\Events\IngestRunStartedLaravelIngest\Events\ChunkProcessedLaravelIngest\Events\RowProcessedLaravelIngest\Events\IngestRunCompletedLaravelIngest\Events\IngestRunFailed
Pruning
To keep your database clean, logs are prunable. Add this to your scheduler:
$schedule->command('model:prune', [ '--model' => [LaravelIngest\Models\IngestRow::class], ])->daily();
π§© Configuration Reference
The IngestConfig fluent API handles complex scenarios with ease.
IngestConfig::for(Product::class) // Sources: UPLOAD, FILESYSTEM, URL, FTP, SFTP ->fromSource(SourceType::FTP, ['disk' => 'erp', 'path' => 'daily.csv']) // Performance ->setChunkSize(1000) ->atomic() // Wrap chunks in transactions // Logic ->keyedBy('sku') ->onDuplicate(DuplicateStrategy::UPDATE_IF_NEWER) ->compareTimestamp('last_modified_at', 'updated_at') // Transformation ->mapAndTransform('price_cents', 'price', fn($val) => $val / 100) ->resolveModelUsing(fn($row) => $row['type'] === 'digital' ? DigitalProduct::class : Product::class);
See the Documentation for all available methods.
π§ͺ Testing
We provide a Docker-based test environment to ensure consistency.
# Start Docker composer docker:up # Run Tests composer docker:test # Check Coverage composer docker:coverage
π€ Contributing
We welcome contributions! Please see CONTRIBUTING.md for details.
π License
The MIT License (MIT). Please see License File for more information.
