PHPackages                             zbm/m2m-seeding - 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. zbm/m2m-seeding

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

zbm/m2m-seeding
===============

seed fake data between many-to-many relation

1.0(1y ago)224MITPHPPHP 8.\*

Since May 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Ziad-B-Almargih/M2MSeeding)[ Packagist](https://packagist.org/packages/zbm/m2m-seeding)[ RSS](/packages/zbm-m2m-seeding/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

M2MSeeding
==========

[](#m2mseeding)

**this package is useful for seeding fake data between two Models with Many-To-Many relationship by some function**

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

[](#installation)

```
composer require zbm/m2m-seeding

```

Usage
-----

[](#usage)

### Basic usage

[](#basic-usage)

```
use m2m\seeding\M2MSeeding;

M2MSeeding::make(FirstModel::class, SecondModel::class, 'relation')
    ->run();
```

- first thing call the static function ***make()*** with the first and second models you need with the name of relation from first model to second model
- then call ***run()*** to seeding the fake data

### Factory the models

[](#factory-the-models)

**if you want to seed the models using factories you can call ***withFactory()*** function**

```
use m2m\seeding\M2MSeeding;

M2MSeeding::make(FirstModel::class, SecondModel::class, 'relation')
    ->withFactory(10, 10)
    ->run();
```

the first parameter is the count of factories in the first model and the second parameter is for second one

### Detect number of relations

[](#detect-number-of-relations)

**you can use this functions to determine number of relations between the models**

```
->minRelation(10)
```

determine the minimum number of relations (the default value is 0).

```
->maxRelation(10)
```

determine the maximum number of relations (the default value is 3).

```
->rangeRelation(2, 5)
```

determine the minimum and maximum number of relations.

### Seed the pivot

[](#seed-the-pivot)

**if the pivot have some data you can also seed it by using withPivot() function**

```
->withPivot(function (){
    return [
        'first_column'  => rand(1, 10),
        'second_column' => fake()->word,
        'third_column'  => true,
    ];
})
```

this function accept callback function returned array of keys (the column name) and values (the value of column)

Example
-------

[](#example)

### First Model

[](#first-model)

```
class Post extends Model{

    public function reactions(){
        return $this->belongsToMany(User::class, 'reactions');
    }
}
```

### Second Model

[](#second-model)

```
class User extends Model{

}
```

### reactions table

[](#reactions-table)

- **id**
- **user\_id**
- **post\_id**
- **reaction\_type**

### Seeding

[](#seeding)

```
use m2m\seeding\M2MSeeding;

M2MSeeding::make(Post::class, User::class, 'reactions')
    ->withFactory(20, 100)
    ->rangeRelation(50, 80)
    ->withPivot(function (){
        return [
            'reaction_type' => rand(1, 6)
        ];
    })
    ->run();
```

**this lines will create 20 Post and 100 User and each Post has between 50 and 80 reactions and each reaction has type as integer between 1 and 6**

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

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

727d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7badbb6f2627d9786b77b92b2cdd4b2629422f001b30371c66b4abd759076bb2?d=identicon)[ziadbanialmargih](/maintainers/ziadbanialmargih)

---

Top Contributors

[![ziad-b-almargih](https://avatars.githubusercontent.com/u/141996400?v=4)](https://github.com/ziad-b-almargih "ziad-b-almargih (4 commits)")

### Embed Badge

![Health badge](/badges/zbm-m2m-seeding/health.svg)

```
[![Health](https://phpackages.com/badges/zbm-m2m-seeding/health.svg)](https://phpackages.com/packages/zbm-m2m-seeding)
```

PHPackages © 2026

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