PHPackages                             alfa6661/laravel-has-many-sync - 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. alfa6661/laravel-has-many-sync

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

alfa6661/laravel-has-many-sync
==============================

Laravel has many sync

1.1.0(7y ago)166.3k11[1 issues](https://github.com/alfa6661/laravel-hasmany-sync/issues)[2 PRs](https://github.com/alfa6661/laravel-hasmany-sync/pulls)MITPHP

Since Aug 10Pushed 5y ago3 watchersCompare

[ Source](https://github.com/alfa6661/laravel-hasmany-sync)[ Packagist](https://packagist.org/packages/alfa6661/laravel-has-many-sync)[ RSS](/packages/alfa6661-laravel-has-many-sync/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Laravel HasMany Sync
====================

[](#laravel-hasmany-sync)

Allow sync method for Laravel Has Many Relationship.

Installation
============

[](#installation)

You can install the package via composer:

```
composer require alfa6661/laravel-has-many-sync

```

Register the ServiceProvider in `config/app.php`

```
'providers' => [
    // ...
    Alfa6661\EloquentHasManySync\ServiceProvider::class,
],
```

Usage
=====

[](#usage)

Setup HasMany Relation
----------------------

[](#setup-hasmany-relation)

```
class Customer extends Model
{
    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function contacts()
    {
        return $this->hasMany(CustomerContact::class);
    }
}
```

You can access the sync method like this:

```
$customer->contacts()->sync([
    [
        'id' => 1,
        'name' => 'Alfa',
        'phone_number' => '123',
    ],
    [
        'id' => null,
        'name' => 'Adhitya',
        'phone_number' => '234,
    ]
]);
```

The sync method accepts an array of data to place on the intermediate table. Any data that are not in the given array will be removed from the intermediate table. So, after this operation is complete, only the data in the given array will exist in the intermediate table:

### Syncing without deleting

[](#syncing-without-deleting)

If you do not want to delete existing data, you may pass false value to the second parameter in the sync method.

```
$customer->contacts()->sync([
    [
        'id' => 1,
        'name' => 'Alfa',
        'phone_number' => '123',
    ],
    [
        'id' => null,
        'name' => 'Adhitya',
        'phone_number' => '234,
    ]
], false);
```

### Example usage in the controller.

[](#example-usage-in-the-controller)

```
class CustomersController extends Controller
{
    /**
     * Update the specified resource in storage.
     *
     * @param  CustomerRequest  $request
     * @param  Customer $customer
     * @return \Illuminate\Http\Response
     */
    public function update(CustomerRequest $request, Customer $customer)
    {
        DB::transaction(function () use ($customer, $request) {
            $customer->update($request->all());
            $customer->contacts()->sync($request->get('contacts', []));
        });

        return redirect()->route('customers.index');
    }
}
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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

Every ~3 days

Total

2

Last Release

2829d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ef0480adb6c2494f21910eb4e69ab92b02e075bfdad37c242fed4f20d0e5412c?d=identicon)[alfa6661](/maintainers/alfa6661)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/alfa6661-laravel-has-many-sync/health.svg)

```
[![Health](https://phpackages.com/badges/alfa6661-laravel-has-many-sync/health.svg)](https://phpackages.com/packages/alfa6661-laravel-has-many-sync)
```

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