PHPackages                             ericphamhoang/belongs-to-many-field - 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. ericphamhoang/belongs-to-many-field

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

ericphamhoang/belongs-to-many-field
===================================

belongsToMany nova representation in field.

0.6.1(6y ago)07MITPHPPHP &gt;=7.1.0

Since Mar 13Pushed 6y agoCompare

[ Source](https://github.com/ericphamhoang/belongs-to-many-field-nova)[ Packagist](https://packagist.org/packages/ericphamhoang/belongs-to-many-field)[ RSS](/packages/ericphamhoang-belongs-to-many-field/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (1)DependenciesVersions (8)Used By (0)

Belongs To Many Field Nova
==========================

[](#belongs-to-many-field-nova)

Belongs To Many field to represent many to many relationship in field. This Field allow attaching relationships easily, you can pass query to the Multiple Select.

[![image](https://user-images.githubusercontent.com/11976865/54318738-46290000-45b5-11e9-8ea0-941adb4b79ba.png)](https://user-images.githubusercontent.com/11976865/54318738-46290000-45b5-11e9-8ea0-941adb4b79ba.png)

### Installation

[](#installation)

```
composer require benjacho/belongs-to-many-field
```

Deprecation
-----------

[](#deprecation)

Method relationModel() no more needed, to prevent conflicts it will be there. And trait HasBelongsToMany no more neede too, both will be in repo, but doesn't work.

### Usage

[](#usage)

To use in nova 1.0 use 0.3 in nova 2.0 use 0.4 and above.

In the resource you need to pass:

- Method make (label, many to many relationship, Nova Resource Relationship)
- Method options (Here you pass options that you need to render in Multiple Select, you can pass Querys, use get() method for that purpose)
- You dont need to pass onlyOnForms(), it is by default.

```
use Benjacho\BelongsToManyField\BelongsToManyField;

public function fields(Request $request){
    BelongsToManyField::make('Role Label', 'roles', 'App\Nova\Role')->options(\App\Role::all()),
}
```

Optional

- Method optionsLabel('columnName'), this method is when you don't have column 'name' in your table and you want to label by another column name. By default it tracks by label 'name'

```
use Benjacho\BelongsToManyField\BelongsToManyField;

public function fields(Request $request){
    BelongsToManyField::make('Role Label', 'roles', 'App\Nova\Role')->options(\App\Role::all())->optionsLabel('title'),
}
```

- Method isAction(), this method is when you need this field in actions, this puts height of field in 350px, and converts in action.

```
use Benjacho\BelongsToManyField\BelongsToManyField;

public function fields(Request $request){
    BelongsToManyField::make('Role Label', 'roles', 'App\Nova\Role')->options(\App\Role::all())->isAction(),
}
```

To obtain the data that is send in action do it:

```
public function handle(ActionFields $fields, Collection $models)
{
    // Get the expenseTypes from the request because the Field BelongsToManyField does not send it

    $values = array_column(json_decode(request()->roles, true),'id');

    foreach ($models as $model) {
        $model->roles()->sync($values);
    }
}
```

### Validations

[](#validations)

This package implement all Laravel Validations, you need to pass the rules in rules method, rules are listed on laravel validations rules for arrays\*.

```
use Benjacho\BelongsToManyField\BelongsToManyField;

public function fields(Request $request){
    BelongsToManyField::make('Role Label', 'roles', 'App\Nova\Role')->options(\App\Role::all())->relationModel(\App\User::class)->rules('required', 'min:1', 'max:5', 'size:3' new CustomRule),
}
```

[![image](https://raw.githubusercontent.com/Benjacho/belongs-to-many-field-nova/master/validation.png)](https://raw.githubusercontent.com/Benjacho/belongs-to-many-field-nova/master/validation.png)

For translations of this validations, use normal laravel validations translations.

### Todo

[](#todo)

Implement validations, implement custom rules

### Contributing

[](#contributing)

-Pull Requests -Issues -Or Contact me:

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.9% 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 ~32 days

Recently: every ~45 days

Total

7

Last Release

2473d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0440f52871baaf86daae4b4099d2e9d2a64c113172f094bfcb8da67e389f7601?d=identicon)[ericphamhoang](/maintainers/ericphamhoang)

---

Top Contributors

[![Benjacho](https://avatars.githubusercontent.com/u/11976865?v=4)](https://github.com/Benjacho "Benjacho (20 commits)")[![ericphamhoangdev](https://avatars.githubusercontent.com/u/268210294?v=4)](https://github.com/ericphamhoangdev "ericphamhoangdev (2 commits)")

---

Tags

laravelnovabelongsToManyMany to Many Field

### Embed Badge

![Health badge](/badges/ericphamhoang-belongs-to-many-field/health.svg)

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

###  Alternatives

[optimistdigital/nova-multiselect-field

A multiple select field for Laravel Nova.

3453.7M8](/packages/optimistdigital-nova-multiselect-field)[benjacho/belongs-to-many-field

belongsToMany nova representation in field.

157866.3k1](/packages/benjacho-belongs-to-many-field)[inspheric/nova-defaultable

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

52178.7k1](/packages/inspheric-nova-defaultable)[datomatic/nova-detached-actions

A Laravel Nova tool to allow for placing actions in the Nova toolbar detached from the checkbox selection mechanism.

11273.0k](/packages/datomatic-nova-detached-actions)

PHPackages © 2026

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