PHPackages                             ajcastro/insert-update-many - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. ajcastro/insert-update-many

ActiveLibrary[Database &amp; ORM](/categories/database)

ajcastro/insert-update-many
===========================

Laravel's batch insert or batch update for collection of eloquent models.

v0.1.0(6y ago)61.6k1MITPHPPHP &gt;=5.4.0

Since Jul 12Pushed 6y agoCompare

[ Source](https://github.com/ajcastro/insert-update-many)[ Packagist](https://packagist.org/packages/ajcastro/insert-update-many)[ RSS](/packages/ajcastro-insert-update-many/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Laravel Eloquent's Insert/Update Many
=====================================

[](#laravel-eloquents-insertupdate-many)

Laravel's batch insert or batch update for collection of eloquent models. Perform single query for batch insert or update operations. This updates the `created_at` and `updated_at` column of the models and the tables. The method names `insertMany` and `updateMany` is based from the eloquent method name `saveMany`. Both `insertMany` and `updateMany` can accept collection of models or just plain array data.

Installation
------------

[](#installation)

```
composer require ajcastro/insert-update-many

```

Usage
-----

[](#usage)

### Insert Many

[](#insert-many)

Directly pass array or collection of models unlike Laravel's built-in `insert()` which only accept arrays. This already sets the `created_at` and `updated_at` columns.

```
$users = factory(User::class, 10)->make();
User::insertMany($users);
```

#### How it works

[](#how-it-works)

The passed collection of models is transformed to its array form, only including fillable attributes, and passed its array form to Laravel's native `insert()` method.

### Update Many

[](#update-many)

Update array or collection of models. This perform a single update query for all the passed models. Only the dirty or changed attributes will be included in the update. This updates the `updated_at` column of the models and the tables.

```
User::updateMany($users); // update many models using id as the default key
User::updateMany($users, 'id'); // same as above
User::updateMany($users, 'username'); // use username as key instead of id
```

#### Specifying which columns to be updated

[](#specifying-which-columns-to-be-updated)

```
User::updateMany($users, 'id', ['email', 'first_name', 'last_name']);
```

#### How it works

[](#how-it-works-1)

This will produce a query like this:

```
UPDATE
   `users`
SET
   `email` =
   CASE
      WHEN
         `id` = '426'
      THEN
         'favian.russel@example.com'
      WHEN
         `id` = '427'
      THEN
         'opurdy@example.org'
      WHEN
         `id` = '428'
      THEN
         'kaylah.hyatt@example.com'
      ELSE
         `email`
   END
, `first_name` =
   CASE
      WHEN
         `id` = '426'
      THEN
         'Orie'
      WHEN
         `id` = '427'
      THEN
         'Hubert'
      WHEN
         `id` = '428'
      THEN
         'Mikayla'
      ELSE
         `first_name`
   END
, `last_name` =
   CASE
      WHEN
         `id` = '426'
      THEN
         'Weissnat'
      WHEN
         `id` = '427'
      THEN
         'Wiza'
      WHEN
         `id` = '428'
      THEN
         'Keeling'
      ELSE
         `last_name`
   END
WHERE
   `id` IN
   (
      426, 427, 428
   );
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2502d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4918318?v=4)[Arjon Jason Castro](/maintainers/ajcastro)[@ajcastro](https://github.com/ajcastro)

---

Top Contributors

[![ajcastro](https://avatars.githubusercontent.com/u/4918318?v=4)](https://github.com/ajcastro "ajcastro (1 commits)")

---

Tags

batch-insertbatch-updateeloquenteloquent-modelslaravelmysql

### Embed Badge

![Health badge](/badges/ajcastro-insert-update-many/health.svg)

```
[![Health](https://phpackages.com/badges/ajcastro-insert-update-many/health.svg)](https://phpackages.com/packages/ajcastro-insert-update-many)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
