PHPackages                             iamkevinmckee/many-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. iamkevinmckee/many-to-many

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

iamkevinmckee/many-to-many
==========================

Easily generate a migration for a many to many relationship

0.2.1(3y ago)31.5k1MITPHPPHP ^7.1|^8.0

Since Feb 13Pushed 3y ago1 watchersCompare

[ Source](https://github.com/iAmKevinMcKee/many-to-many)[ Packagist](https://packagist.org/packages/iamkevinmckee/many-to-many)[ Docs](https://github.com/iamkevinmckee/many-to-many)[ RSS](/packages/iamkevinmckee-many-to-many/feed)WikiDiscussions master Synced 3w ago

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

Generate Many to Many Migrations
================================

[](#generate-many-to-many-migrations)

When you want to make a [many to many](https://laravel.com/docs/8.x/eloquent-relationships#many-to-many) relationship in Laravel, you need to create a pivot table. This package gives you a command to generate the migration for that pivot table automatically.

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

[](#installation)

You can install the package via composer:

```
composer require iamkevinmckee/many-to-many --dev
```

Usage
-----

[](#usage)

When you need to create a pivot table for a many to many relationship, just run the following command:

```
php artisan many-to-many FirstModel SecondModel
```

For example:

```
php artisan many-to-many tag post
```

This will generate a migration with the following `up` method:

```
public function up()
{
    Schema::create('post_tag', function (Blueprint $table) {
        $table->unsignedBigInteger('post_id');
        $table->unsignedBigInteger('tag_id');
        $table->foreign('post_id')->references('id')->on('posts')
            ->onDelete('cascade');
        $table->foreign('tag_id')->references('id')->on('tags')
            ->onDelete('cascade');
    });
}
```

Then you only need to run the migrate command and add the relationship to the models.

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

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Kevin McKee](https://github.com/iamkevinmckee)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

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

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

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

Every ~270 days

Total

4

Last Release

1149d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4503765?v=4)[Kevin McKee](/maintainers/iamkevinmckee)[@iAmKevinMcKee](https://github.com/iAmKevinMcKee)

---

Top Contributors

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

---

Tags

many to manyiamkevinmckee

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/iamkevinmckee-many-to-many/health.svg)

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

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k54.1M11.1k](/packages/illuminate-database)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.1M23](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.4M2](/packages/glushkovds-phpclickhouse-laravel)[lemaur/eloquent-publishing

207.8k1](/packages/lemaur-eloquent-publishing)[laravel-liberu/laravel-gedcom

A package that converts gedcom files to Eloquent models

782.5k1](/packages/laravel-liberu-laravel-gedcom)

PHPackages © 2026

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