PHPackages                             waelmoh/laravel-update-insert-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. waelmoh/laravel-update-insert-many

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

waelmoh/laravel-update-insert-many
==================================

Laravel Batch insert or batch update collection of models

v2.0.3(3y ago)465MITPHPPHP &gt;=8.0.0

Since Jun 12Pushed 3y ago1 watchersCompare

[ Source](https://github.com/WMOH-DEV/Laravel-UpdateMany-InsertMany)[ Packagist](https://packagist.org/packages/waelmoh/laravel-update-insert-many)[ RSS](/packages/waelmoh-laravel-update-insert-many/feed)WikiDiscussions master Synced today

READMEChangelog (8)DependenciesVersions (10)Used By (0)

Laravel Update Many
===================

[](#laravel-update-many)

Laravel batch update a collection of eloquent models. Perform single query for batch update collection of models. It will also update `updated_at` column of the models

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

[](#installation)

```
composer require waelmoh/laravel-update-insert-many

```

Usage
-----

[](#usage)

### Update Many

[](#update-many)

Update collection of models. This perform a single update query for all the passed models. Accepts an array of arrays or collection. Each array|object should contain the model key and the data to update. The key can be any column, by default it is `id`. Also key can be an array of columns.

Only the dirty or changed attributes will be included in the update. This updates the `updated_at` column of the models and the tables.

```
$users = [
   [
      'id'         => 31,
      'first_name' => 'John',
      'last_name'  => 'Doe',
      'email'      => 'John@Doe.com'

   ],
   [
      'id'         => 32,
      'first_name' => 'Hubert',
      'last_name'  => 'Wiza',
      'email'      => 'Hubert@Wiza.org'
   ],
   [
      'id'         => 33,
      'first_name' => 'Mikayla',
      'last_name'  => 'Keeling',
      'email'      => 'Mikayla.hyatt@example.com'
      ]
]
```

```
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
User::updateMany($users, ['username', 'email']); // use username and email as keys instead of id
User::updateMany($users, ['username', 'email'], ['last_name']); // update last name if username and email match
```

#### 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)

This will produce a query like this:

```
UPDATE
   `users`
SET
   `email` =
   CASE
      WHEN
         `id` = '31'
      THEN
         'John@Doe.com'
      WHEN
         `id` = '32'
      THEN
         'Hubert@Wiza.org'
      WHEN
         `id` = '33'
      THEN
         'Mikayla.hyatt@example.com'
      ELSE
         `email`
   END
, `first_name` =
   CASE
      WHEN
         `id` = '31'
      THEN
         'John'
      WHEN
         `id` = '32'
      THEN
         'Hubert'
      WHEN
         `id` = '33'
      THEN
         'Mikayla'
      ELSE
         `first_name`
   END
, `last_name` =
   CASE
      WHEN
         `id` = '31'
      THEN
         'Doe'
      WHEN
         `id` = '32'
      THEN
         'Wiza'
      WHEN
         `id` = '33'
      THEN
         'Keeling'
      ELSE
         `last_name`
   END
WHERE
   `id` IN
   (
      31, 32, 33
   );
```

#### Rights

[](#rights)

##### This package inspired, forked from \[ajcastro\] and developed by \[waelmoh\].

[](#this-package-inspired-forked-from-ajcastro-and-developed-by-waelmoh)

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 56.3% 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

Every ~20 days

Recently: every ~0 days

Total

8

Last Release

1342d ago

Major Versions

v1.1.1 → v2.0.02022-10-29

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/86940720?v=4)[WaelMoH](/maintainers/WaelMoH)[@waelmoh](https://github.com/waelmoh)

---

Top Contributors

[![WMOH-DEV](https://avatars.githubusercontent.com/u/58665715?v=4)](https://github.com/WMOH-DEV "WMOH-DEV (9 commits)")[![WaelMohElSaid](https://avatars.githubusercontent.com/u/108067872?v=4)](https://github.com/WaelMohElSaid "WaelMohElSaid (7 commits)")

### Embed Badge

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

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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