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)464MITPHPPHP &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 1mo ago

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 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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

1291d ago

Major Versions

v1.1.1 → v2.0.02022-10-29

### Community

Maintainers

![](https://www.gravatar.com/avatar/9c7b1bbcedb0704c1a16c8700183635b488f4e2a6e122b8d0eb9796a5ddfc435?d=identicon)[WaelMoH](/maintainers/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

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