mavinoo/laravel-batch
Batch insert/bulk update helper for Laravel Eloquent. Update many rows in one query using an index key, or update per-row with multiple conditions. Includes Facade and helper access (Batch:: or batch()) for fast mass data changes.
last_login < 30 days").Adopt When:
User::batchUpdate() vs. manual foreach loops).Look Elsewhere If:
WHERE EXISTS (SELECT ...)).For Executives: *"This package slashes database load for bulk operations, cutting costs and improving scalability. For example:
For Engineers: *"Laravel Batch gives us batteries-included bulk operations with:
composer require and use User::batchUpdate().update(): Bulk updates by index (e.g., id).updateMultipleCondition(): Per-row conditions (e.g., WHERE id=1 AND status='active').increment/decrement(): Arithmetic ops (e.g., balance += 100).insert(): Chunked inserts (configurable batch size).use HasBatch to any Eloquent model.Tradeoffs:
DB::transaction() if needed.Example Use Case:
// Update 10K users' statuses in 1 query (vs. 10K queries)
User::batchUpdate([
['id' => 1, 'status' => 'active'],
['id' => 2, 'status' => 'inactive'],
// ... 10K more
], 'id');
// Insert 50K records in chunks of 500
User::batchInsert(['name', 'email'], $usersData, 500);
```*
**For PMs**:
*"This lets us **ship bulk features faster** without over-engineering. Prioritize it for:
1. **Data-heavy features** (e.g., imports, migrations).
2. **Admin tools** (e.g., bulk user edits).
3. **Performance-critical paths** (e.g., nightly syncs).
**Avoid** if you need real-time consistency or complex logic. Pair with `DB::transaction()` for critical paths."*
How can I help you explore Laravel packages today?