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

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

dynamicnet/many-to-many
=======================

A Laravel Nova field.

1.0.1(2y ago)0206MITPHPPHP &gt;=7.1.0

Since Jul 13Pushed 2y ago1 watchersCompare

[ Source](https://github.com/dynamicnet/many-to-many)[ Packagist](https://packagist.org/packages/dynamicnet/many-to-many)[ RSS](/packages/dynamicnet-many-to-many/feed)WikiDiscussions master Synced 1mo ago

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

ManyToMany
==========

[](#manytomany)

A Laravel Nova field for polymorphic and non-polymorphic `ManyToMany` relationships.

##### Table of Contents

[](#table-of-contents)

- [Features](#features)
- [Install](#install)
- [Simple Usage](#simple-usage)
- [Pivots](#pivots)
- [Duplicate Attachment](#duplicate-attachment)
- [Polymorphic Relation](#polymorphic-relation)
- [Fill Using](#fill-using)

Features
--------

[](#features)

- Attach polymorphic and non-polymorphic `ManyToMany` relationships in the creation and update page
- Edit pivot columns when attaching relation
- Attach a source to another resource many times

Install
-------

[](#install)

```
composer require martinjuul/many-to-many
```

Simple Usage
------------

[](#simple-usage)

```
  use Juul\Fields\BelongsToMany;

  /**
   * Get the fields displayed by the resource.
   *
   * @param  \Illuminate\Http\Request  $request
   * @return array
   */
  public function fields(Request $request)
  {
    return [
      BelongsToMany::make(__("Label"), 'relationName', RelatedResource::class)
          ->fields(function() {
              return [
                  Text::make('Price')
                          ->rules('required', 'numeric'),
              ];
          })
          ->pivots(),
    ];
  }

```

Pivots
------

[](#pivots)

For customizing the pivot columns when attaching a resource you can use the `pivots` method of the field. then define your custom pivot fields with the `fields` method. now, when attaching a resource; a Modal that contains the pivot fields will be displayed to you.

```
  use Juul\Fields\BelongsToMany;

  /**
   * Get the fields displayed by the resource.
   *
   * @param  \Illuminate\Http\Request  $request
   * @return array
   */
  public function fields(Request $request)
  {
    return [
      BelongsToMany::make(__("Label"), 'relationName', RelatedResource::class)
          ->fields(function() {
              return [
                  Text::make('Price')
                          ->rules('required', 'numeric'),
              ];
          })
          ->pivots(),
    ];
  }

```

Duplicate Attachment
--------------------

[](#duplicate-attachment)

You can use the `duplicate` feature for repetitively attach a resource to another resource. follow the example:

```
  use Juul\Fields\BelongsToMany;

  /**
   * Get the fields displayed by the resource.
   *
   * @param  \Illuminate\Http\Request  $request
   * @return array
   */
  public function fields(Request $request)
  {
    return [
      BelongsToMany::make(__("Label"), 'relationName', RelatedResource::class)
          ->fields(function() {
              return [
                  Text::make('Price')
                          ->rules('required', 'numeric'),
              ];
          })
          ->duplicate(),
    ];
  }

```

Polymorphic Relation
--------------------

[](#polymorphic-relation)

Using for the polymorphic relationships is like non-polymorphic. follow the example:

```
  use Juul\Fields\MorphToMany;

  /**
   * Get the fields displayed by the resource.
   *
   * @param  \Illuminate\Http\Request  $request
   * @return array
   */
  public function fields(Request $request)
  {
    return [
      MorphToMany::make(__("Label"), 'relationName', RelatedResource::class)
          ->fields(function() {
              return [
                  Text::make('Price')
                          ->rules('required', 'numeric'),
              ];
          })
          ->duplicate()
          ->pivots(),
    ];
  }

```

or

```
  use Juul\Fields\MorphedByMany;

  /**
   * Get the fields displayed by the resource.
   *
   * @param  \Illuminate\Http\Request  $request
   * @return array
   */
  public function fields(Request $request)
  {
    return [
      MorphedByMany::make(__("Label"), 'relationName', RelatedResource::class)
          ->fields(function() {
              return [
                  Text::make('Price')
                          ->rules('required', 'numeric'),
              ];
          })
          ->duplicate()
          ->pivots(),
    ];
  }

```

Fill Using
----------

[](#fill-using)

You can use `fillUsing` to change the pivot-columns values; Then you need to return an associative array that matches your pivot table. Be careful; the "fillUsing" method applies to each attachment. see the following example:

```
  ->fillUsing(function($pivots) {
      if(isset($pivots['options']) && is_array($pivots['options'])) {
          $pivots['options'] = json_encode($pivots['options']);
      }

      return $pivots;
  }),

```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

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

1031d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/78d53a6a8c98ebbd71ef48e37f1d2a48b9a7438f611b98e9d3bf7e60d694827a?d=identicon)[dynamicnet](/maintainers/dynamicnet)

---

Tags

laravelnovamartinjuulmartin-juul

### Embed Badge

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

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

###  Alternatives

[optimistdigital/nova-multiselect-field

A multiple select field for Laravel Nova.

3403.5M7](/packages/optimistdigital-nova-multiselect-field)[digital-creative/conditional-container

Provides an easy way to conditionally show and hide fields in your Nova resources.

116593.8k4](/packages/digital-creative-conditional-container)[genealabs/laravel-overridable-model

Provide a uniform method of allowing models to be overridden in Laravel.

92398.0k2](/packages/genealabs-laravel-overridable-model)[inspheric/nova-defaultable

Default values for Nova fields when creating resources and running resource actions.

51174.8k1](/packages/inspheric-nova-defaultable)[murdercode/nova4-tinymce-editor

Boost your Laravel Nova with the TinyMCE editor.

17165.2k](/packages/murdercode-nova4-tinymce-editor)[yieldstudio/nova-google-autocomplete

A Laravel Nova Google autocomplete field.

12218.4k](/packages/yieldstudio-nova-google-autocomplete)

PHPackages © 2026

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