zappzerapp/laravel-ingest
Composer 安装命令:
composer require zappzerapp/laravel-ingest
包简介
A robust, configuration-driven ETL and data import framework for Laravel. Handles CSV/Excel streaming, queues, validation, and relationships.
README 文档
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
Use the Artisan generator to scaffold a new importer:
php artisan make:importer UserImporter --model=User
Alternatively, create a class implementing IngestDefinition manually:
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
💡 Demo Project
Want to see Laravel Ingest in action? Check out our Laravel Ingest Demo repository for a complete working example.
# Clone the demo git clone https://github.com/zappzerapp/Laravel-Ingest-Demo.git cd Laravel-Ingest-Demo # Start and benchmark docker compose up -d docker compose exec app php artisan benchmark:ingest
🛠 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. |
ingest:prune-files |
Remove temporary import files older than the configured TTL. |
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.
✨ Advanced Features
Beyond the basics, Laravel Ingest supports advanced capabilities for complex import scenarios:
- Validators — Rule-based and custom validators to reject rows before processing.
- Transformers & Pipelines — Chain multiple transformations on field values.
- Conditional Mappings — Apply mappings only when row conditions are met.
- Custom Sources — Define your own source types (e.g., database, API).
- Import Event Handlers — React to lifecycle events (start, progress, complete, failure).
- Nested Mappings — Handle nested data structures and one-to-many relationships.
- Schema Validation — Validate the structure of your file before processing.
- Tracing & Debugging — Inspect row-level decision trees and resolve issues fast.
🧪 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.
zappzerapp/laravel-ingest 适用场景与选型建议
zappzerapp/laravel-ingest 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.45k 次下载、GitHub Stars 达 103, 最近一次更新时间为 2025 年 12 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「queue」 「excel」 「csv」 「import」 「streaming」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zappzerapp/laravel-ingest 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zappzerapp/laravel-ingest 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zappzerapp/laravel-ingest 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This Symfony bundle integrates PhpSpreadsheet into Symfony using Twig.
PHP AMQP Binding Library
A Laravel package to monitor queue jobs.
PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine
Yii2 export extension
PHP Excel Library
统计信息
- 总下载量: 2.45k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 103
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-02
