PHPackages                             haithemkdous/laravel-7-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. haithemkdous/laravel-7-has-many-sync

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

haithemkdous/laravel-7-has-many-sync
====================================

Laravel has many sync

1.2.0(5y ago)017MITPHP

Since Aug 10Pushed 2y agoCompare

[ Source](https://github.com/haithemkdous/laravel-hasmany-sync)[ Packagist](https://packagist.org/packages/haithemkdous/laravel-7-has-many-sync)[ RSS](/packages/haithemkdous-laravel-7-has-many-sync/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (4)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 haithemkdous/laravel-7-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

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% 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 ~441 days

Total

3

Last Release

1952d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/57354581fc5183e6948b5ff544ffc0d0fe31dec6745bedaa2d2676ecfbdcb514?d=identicon)[haithemkdous](/maintainers/haithemkdous)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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