PHPackages                             jmjl161100/laravel-relation-updater - 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. jmjl161100/laravel-relation-updater

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

jmjl161100/laravel-relation-updater
===================================

Elegant and declarative model relation updater for Laravel.

v1.0.0(1y ago)0664MITPHPPHP ^8.2

Since Apr 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/jmjl161100/laravel-relation-updater)[ Packagist](https://packagist.org/packages/jmjl161100/laravel-relation-updater)[ RSS](/packages/jmjl161100-laravel-relation-updater/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/e2df0db5111cc996698331f261bf2635d5d982b997163dd61bcd20b2f000f216/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e322d3838393242462e737667)](https://www.php.net/)[![Laravel Version](https://camo.githubusercontent.com/e9bc60ad3f03c5ec80d86d3bc0c83b61348854be1307653edefc3ef6e8f121db/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d25354531312e302d4646324432302e737667)](https://laravel.com)

Laravel Relation Updater
========================

[](#laravel-relation-updater)

> Elegant and declarative model relation updater for Laravel.

✨ Features
----------

[](#-features)

- ✅ Simple, expressive API for updating Eloquent relationships
- ✅ Supports multiple relation types (`hasOne`, `hasMany`, etc.)
- ✅ Laravel 11+ ready
- ✅ PHP 8.2+ support
- ✅ Returns detailed result collections: created, updated, deleted

📦 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require jmjl161100/laravel-relation-updater
```

The service provider will be auto-registered via Laravel package discovery.

🚀 Quick Start
-------------

[](#-quick-start)

### 1. Use the Trait in Your Model

[](#1-use-the-trait-in-your-model)

```
use Illuminate\Database\Eloquent\Model;
use Jmjl161100\RelationUpdater\Traits\HasRelationUpdater;

class Post extends Model
{
    use HasRelationUpdater;

    public function comments()
    {
        return $this->hasMany(Comment::class);
    }
}
```

### 2. Update Relations with `{relationName}Update`

[](#2-update-relations-with-relationnameupdate)

```
$post = Post::find(1);

$result = $post->commentsUpdate([
    ['id' => 1, 'content' => 'Updated comment'], // Update
    ['content' => 'New comment']                // Create
]);
```

### 3. Get Operation Results

[](#3-get-operation-results)

The returned result is an array of model collections:

```
[
    'created' => Collection, // Newly created models
    'updated' => Collection, // Updated models
    'deleted' => Collection  // Models deleted due to sync
]
```

⚙️ Advanced Usage
-----------------

[](#️-advanced-usage)

### Field Mapping

[](#field-mapping)

If input keys differ from model attributes, provide a mapping:

```
$post->commentsUpdate(
                        [
                            ['id' => 1, 'input_content' => 'Updated comment']
                        ],
                        [
                            'input_content' => 'content'
                        ]
                     );
```

This maps `input_content` to the model's `content` attribute.

🛡 Security
----------

[](#-security)

If you discover a security vulnerability, please **do not** open an issue. Instead, contact the author directly.

📄 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance48

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

387d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8239522181ae7c93847a2cf5e03082ebdb18406d7b43ba7df1c0b19880711d23?d=identicon)[jmjl161100](/maintainers/jmjl161100)

---

Top Contributors

[![jmjl161100](https://avatars.githubusercontent.com/u/207161202?v=4)](https://github.com/jmjl161100 "jmjl161100 (3 commits)")

###  Code Quality

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/jmjl161100-laravel-relation-updater/health.svg)

```
[![Health](https://phpackages.com/badges/jmjl161100-laravel-relation-updater/health.svg)](https://phpackages.com/packages/jmjl161100-laravel-relation-updater)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[overtrue/laravel-versionable

Make Laravel model versionable.

585308.0k5](/packages/overtrue-laravel-versionable)[abbasudo/laravel-purity

elegant way to add filter and sort in laravel

514330.5k1](/packages/abbasudo-laravel-purity)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135192.6k5](/packages/statamic-rad-pack-runway)[dragon-code/laravel-deploy-operations

Performing any actions during the deployment process

240173.5k2](/packages/dragon-code-laravel-deploy-operations)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)

PHPackages © 2026

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