PHPackages                             elbgoods/eloquent-sync-one-to-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. elbgoods/eloquent-sync-one-to-many

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

elbgoods/eloquent-sync-one-to-many
==================================

0.3.0(6y ago)85003MITPHPPHP ^7.4CI failing

Since Mar 4Pushed 5y ago3 watchersCompare

[ Source](https://github.com/elbgoods/eloquent-sync-one-to-many)[ Packagist](https://packagist.org/packages/elbgoods/eloquent-sync-one-to-many)[ Docs](https://github.com/elbgoods/laravel-sync-one-to-many)[ RSS](/packages/elbgoods-eloquent-sync-one-to-many/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (3)Dependencies (4)Versions (4)Used By (0)

Laravel Sync OneToMany
======================

[](#laravel-sync-onetomany)

This package provides the sync function for one to many relations similar to the sync method from BelongsToMany.

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

[](#installation)

You can install the package via composer:

```
composer require elbgoods/eloquent-sync-one-to-many
```

Usage
-----

[](#usage)

Sync using ids

```
$user->tasks()->sync([1, 2, 4]);
```

Sync using ids and additional attributes

```
$user->tasks()->sync([
    1 => ['status' => 'wip', 'priority' => 1],
    4 => ['status' => 'finished', 'priority' => 3],
]);
```

Sync without detaching

```
$user->tasks()->syncWithoutDetaching([1, 2, 4]);

// or

$user->tasks()->sync([1, 2, 4], ['detaching' => false]);
```

Sync and set additional attributes to detached

```
$user->tasks()->sync(
    [1, 2, 4],
    'set_after_detach' => [
        'status' => 'open',
        'priority' => 0,
    ],
);
```

Sync using values by given key as ids

```
$user->tasks()->sync([
    ['task_id' => 1, 'status' => 'wip', 'priority' => 1],
    ['task_id' => 4, 'status' => 'finished', 'priority' => 3],
], [foreign_id_key => 'task_id']);
```

Result is the same as the result of the sync method of `BelongsToMany`, an array with attach, detached and updated rows.

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

Please see [SECURITY](SECURITY.md) for details.

Credits
-------

[](#credits)

- [Niclas Schirrmeister](https://github.com/eisfeuer)
- [Tom Witkowski](https://github.com/gummibeer)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Treeware
--------

[](#treeware)

You're free to use this package, but if it makes it to your production environment we would highly appreciate you buying or planting the world a tree.

It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to [plant trees](https://www.bbc.co.uk/news/science-environment-48870920). If you contribute to my forest you’ll be creating employment for local families and restoring wildlife habitats.

You can buy trees at

Read more about Treeware at

[![We offset our carbon footprint via Offset Earth](https://camo.githubusercontent.com/3c7b612cd33ceabed721a1325651b948c1425f67e0b1c11a6e871b5e90635476/68747470733a2f2f746f6f6c6b69742e6f66667365742e65617274682f636172626f6e706f736974697665776f726b666f7263652f62616467652f3565313836653638353136656236303031386335313732623f626c61636b3d74727565266c616e6473636170653d74727565)](https://offset.earth/treeware)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 69.2% 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 ~17 days

Total

3

Last Release

2232d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6187884?v=4)[Tom Herrmann](/maintainers/Gummibeer)[@Gummibeer](https://github.com/Gummibeer)

![](https://www.gravatar.com/avatar/33a11c820ca1801a2b0cc065786385f9a1746ae02d1a120102ea7fc7f545eeb7?d=identicon)[Elbgoods](/maintainers/Elbgoods)

---

Top Contributors

[![Gummibeer](https://avatars.githubusercontent.com/u/6187884?v=4)](https://github.com/Gummibeer "Gummibeer (9 commits)")[![eisfeuer](https://avatars.githubusercontent.com/u/12658491?v=4)](https://github.com/eisfeuer "eisfeuer (4 commits)")

---

Tags

elbgoodslaravel-sync-one-to-many

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/elbgoods-eloquent-sync-one-to-many/health.svg)

```
[![Health](https://phpackages.com/badges/elbgoods-eloquent-sync-one-to-many/health.svg)](https://phpackages.com/packages/elbgoods-eloquent-sync-one-to-many)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[genealabs/laravel-pivot-events

This package introduces new eloquent events for sync(), attach(), detach() or updateExistingPivot() methods on BelongsToMany relation.

1404.9M8](/packages/genealabs-laravel-pivot-events)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)

PHPackages © 2026

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