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.
Strengths:
Batch::update()) and helper (batch()->update()) patterns.updateMultipleCondition() method enables row-specific updates (e.g., WHERE id=1 AND status='active'), addressing edge cases where simple WHERE IN clauses fall short.balance += 100), ideal for financial systems or counters.HasBatch trait enables model-level batch operations (e.g., User::batchUpdate()), reducing facade dependency and improving encapsulation.Gaps:
DB::transaction() wrapping for atomicity.eloquent.saving), limiting pre/post-processing hooks (e.g., logging, validation).deleted_at columns; requires manual handling for soft-deleted models (e.g., filtering out deleted records before batch operations).WHERE IN or conditional clauses. Complex joins/subqueries require raw SQL or Eloquent queries.DB::transaction() or implement custom rollback logic.NULL, empty strings). Mitigation: Validate input data before batch operations.SELECT ... FOR UPDATE) if needed.batchSize accordingly.)UPDATE with ON CONFLICT, and custom backtick disabling.php artisan batch:import).foreach loops).BatchService) for easier swapping if needed.foreach ($users) { $user->update(...); } with Batch::update($users, $data, 'id').foreach loops) may need refactoring to adopt batch operations.Batch::insert().Batch::insert($model, $columns, $values, $batchSize).WHERE id IN (...)) with `BatchHow can I help you explore Laravel packages today?