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

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

armincms/many-to-many
=====================

A Laravel Nova field.

1.2.1(3y ago)2574.7k↓24.3%15[9 issues](https://github.com/armincms/many-to-many/issues)[6 PRs](https://github.com/armincms/many-to-many/pulls)3MITPHPPHP &gt;=7.1.0

Since Feb 15Pushed 3y ago1 watchersCompare

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

READMEChangelog (10)Dependencies (1)Versions (19)Used By (3)

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)
- [Searching](#searching)
- [Pivots](#pivots)
- [Duplicate Attachment](#duplicate-attachment)
- [Polymorphic Relation](#polymorphic-relation)
- [Fill Using](#fill-using)
- [Filter Related Resources](#filter-related-resources)

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 armincms/many-to-many
```

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

[](#simple-usage)

```
  use Armincms\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(),
    ];
  }

```

Searching
---------

[](#searching)

To search relation value instead of select it; you can use the `searchable` method on the field.

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.

In addition to the pivot columns, the pivot table should have its own `id` column which must be mentioned in the model definition.

```
