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.
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.
Full documentation is available at zappzerapp.github.io/laravel-ingest.
composer require zappzerapp/laravel-ingest
# Publish config & migrations
php artisan vendor:publish --provider="LaravelIngest\IngestServiceProvider"
# Create tables
php artisan migrateCreate 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'
]);
}
}In App\Providers\AppServiceProvider:
use LaravelIngest\IngestServiceProvider;
public function register(): void
{
$this->app->tag([UserImporter::class], IngestServiceProvider::INGEST_DEFINITION_TAG);
}You can now trigger the import via CLI or API.
Via Artisan (Backend / Cron):
php artisan ingest:run user-importer --file=users.csvVia API (Frontend / Upload):
curl -X POST \
-H "Authorization: Bearer <token>" \
-F "[email protected]" \
https://your-app.com/api/v1/ingest/upload/user-importerIngest 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. |
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.
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
To keep your database clean, logs are prunable. Add this to your scheduler:
$schedule->command('model:prune', [
'--model' => [LaravelIngest\Models\IngestRow::class],
])->daily();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.
We provide a Docker-based test environment to ensure consistency.
# Start Docker
composer docker:up
# Run Tests
composer docker:test
# Check Coverage
composer docker:coverageWe welcome contributions! Please see CONTRIBUTING.md for details.
The MIT License (MIT). Please see License File for more information.
