PHPackages                             thienkimlove/nova-dependency-container - 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. thienkimlove/nova-dependency-container

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

thienkimlove/nova-dependency-container
======================================

A Laravel Nova field container allowing to depend on other fields values

1.2.10(6y ago)06MITPHPPHP &gt;=7.1.0

Since Sep 13Pushed 5y agoCompare

[ Source](https://github.com/thienkimlove/nova-dependency-container)[ Packagist](https://packagist.org/packages/thienkimlove/nova-dependency-container)[ RSS](/packages/thienkimlove-nova-dependency-container/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (24)Used By (0)

Nova Field Dependency Container
===============================

[](#nova-field-dependency-container)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4d8728be49ec249ac80f7d822136980490ca50f491283f652dd431b3036127cc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746869656e6b696d6c6f76652f6e6f76612d646570656e64656e63792d636f6e7461696e65722e737667)](https://packagist.org/packages/thienkimlove/nova-dependency-container)[![Total Downloads](https://camo.githubusercontent.com/87d1426ed7c6b7a53fd7fca375de75d49eb089a674c0f196e9b2e021b825bf0a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746869656e6b696d6c6f76652f6e6f76612d646570656e64656e63792d636f6e7461696e65722e737667)](https://packagist.org/packages/thienkimlove/nova-dependency-container)[![License](https://camo.githubusercontent.com/b0e4b426f122c09e07f306dd72f960d68cc16a78e66ea53ae189a8bb8e95a79b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746869656e6b696d6c6f76652f6e6f76612d646570656e64656e63792d636f6e7461696e65722e737667)](https://github.com/thienkimlove/nova-dependency-container/blob/master/LICENSE.md)

### Description

[](#description)

A container for grouping fields that depend on other field values. Dependencies can be set on any field type or value.

### Demo

[](#demo)

[![Demo](https://raw.githubusercontent.com/thienkimlove/nova-dependency-container/master/docs/demo.gif)](https://raw.githubusercontent.com/thienkimlove/nova-dependency-container/master/docs/demo.gif)

### Versions

[](#versions)

- install v1.2.x for Laravel v5.8 or v6.x and Nova 2.x
- install v1.1.2 for Laravel v5.7 and Nova v1.x

### Installation

[](#installation)

The package can be installed through Composer.

```
composer require thienkimlove/nova-dependency-container
```

### Usage

[](#usage)

1. Add the `Thienkimlove\NovaDependencyContainer\HasDependencies` trait to your Nova Resource.
2. Add the `Thienkimlove\NovaDependencyContainer\NovaDependencyContainer` to your Nova Resource `fields` method.

```
class Page extends Resource
{
    use HasDependencies;

    public function fields(Request $request)
    {
        return [

            Select::make('Name format', 'name_format')->options([
                0 => 'First Name',
                1 => 'First Name / Last Name',
                2 => 'Full Name'
            ])->displayUsingLabels(),

            NovaDependencyContainer::make([
                Text::make('First Name', 'first_name')
            ])->dependsOn('name_format', 0),

        ];
    }
}
```

### Dependencies

[](#dependencies)

The package supports four kinds of dependencies:

1. `->dependsOn('field', 'value')`
2. `->dependsOnNot('field', 'value')`
3. `->dependsOnEmpty('field')`
4. `->dependsOnNotEmpty('field')`
5. `->dependsOnNullOrZero('field')`

These dependencies can be combined by chaining the methods on the `NovaDependencyContainer`:

```
NovaDependencyContainer::make([
  // dependency fields
])
->dependsOn('field1', 'value1')
->dependsOnNotEmpty('field2')
->dependsOn('field3', 'value3')
```

The fields used as dependencies can be of any Laravel Nova field type. Currently only two relation field types are supported, `BelongsTo` and `MorphTo`.

Here is an example using a checkbox:

[![Demo](https://raw.githubusercontent.com/thienkimlove/nova-dependency-container/master/docs/demo-2.gif)](https://raw.githubusercontent.com/thienkimlove/nova-dependency-container/master/docs/demo-2.gif)

### BelongsTo dependency

[](#belongsto-dependency)

If we follow the example of a *Post model belongsTo a User model*, taken from Novas documentation [BelongsTo](https://nova.laravel.com/docs/2.0/resources/relationships.html#belongsto), the dependency setup has the following construction.

We use the singular form of the `belongsTo` resource in lower case, in this example `Post` becomes `post`. Then we define in dot notation, the property of the resource we want to depend on. In this example we just use the `id` property, as in `post.id`.

```
BelongsTo::make('Post'),

NovaDependencyContainer::make([
    Boolean::make('Visible')
])
->dependsOn('post.id', 2)
```

When the `Post` resource with `id` 2 is being selected, a `Boolean` field will appear.

### BelongsToMany dependency

[](#belongstomany-dependency)

A [BelongsToMany](https://nova.laravel.com/docs/2.0/resources/relationships.html#belongstomany) setup is similar to that of a [BelongsTo](https://nova.laravel.com/docs/2.0/resources/relationships.html#belongsto).

The `dependsOn` method should be pointing to the name of the intermediate table. If it is called `role_user`, the setup should be

```
BelongsToMany::make('Roles')
	->fields(function() {
		return [
			NovaDependencyContainer::make([
			    // pivot field rules_all
			    Boolean::make('Rules All', 'rules_all')
			])
			->dependsOn('role_user', 1)
		]
	}),
```

If the pivot field name occurs multiple times, consider using [custom intermediate table models](https://laravel.com/docs/6.x/eloquent-relationships#defining-custom-intermediate-table-models) and define it in the appropiate model relation methods. The only reliable solution I found was using mutators to get/set a field which was being used multiple times. Although this may seem ugly, the events which should be fired on the intermediate model instance, when using an Observer, would work unreliable with every new release of Nova.

> If Nova becomes reliable firing eloquent events on the intermediate table, I will update this examples with a more elegant approach using events instead.

Here is an (ugly) example of a get/set mutator setup for an intermediate table using a pivot field called `type`.

```
// model User
class User ... {

   public function roles() {
   		return $this->belongsToMany->using(RoleUser::class)->withPivot('rules_all');
   }

}

// model Role
class Role ... {

   public function users() {
   		return $this->belongsToMany->using(RoleUser::class)->withPivot('rules_all');
   }

}

// intermediate table
use Illuminate\Database\Eloquent\Relations\Pivot;
class RoleUser extends Pivot {

	protected $table 'role_user';

	public function getType1Attribute() {
	    return $this->type;
	}

	public function setType1Attribute($value) {
		$this->attributes['type'] = $value;
	}

	// ... repeat for as many types as needed
}
```

And now for the dependency container.

```
->fields(function() {
	return [
		NovaDependencyContainer::make([
		    // pivot field rules_all
		    Select::make('Type', 'type_1')
		    	->options([
		    		/* some options */
	    		])
		    	->displayUsingLabels()
		])
		->dependsOn('role_user', 1)
		,

		NovaDependencyContainer::make([
		    // pivot field rules_all
		    Select::make('Type', 'type_2')
		    	->options([
		    		/* different options */
	    		])
		    	->displayUsingLabels()
		])
		->dependsOn('role_user', 2)
		,

		// .. and so on
	]
}),
```

### MorphTo dependency

[](#morphto-dependency)

A similar example taken from Novas documentation for [MorphTo](https://nova.laravel.com/docs/2.0/resources/relationships.html#morphto) is called commentable. It uses 3 Models; `Comment`, `Video` and `Post`. Here `Comment` has the morphable fields `commentable_id` and `commentable_type`

For a `MorphTo` dependency, the following construction is needed.

`Commentable` becomes lower case `commentable` and the value to depend on is the resource singular form. In this example the dependency container will add two additional fields, `Additional Text` and `Visible`, only when the `Post` resource is selected.

```
MorphTo::make('Commentable')->types([
    Post::class,
    Video::class,
]),

NovaDependencyContainer::make([
    Text::make('Additional Text', 'additional'),
    Boolean::make('Visible', 'visible')
])
->dependsOn('commentable', 'Post')
```

### License

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/thienkimlove/nova-dependency-container/blob/master/LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~21 days

Recently: every ~12 days

Total

22

Last Release

2351d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d612ca3d55907bd300c57f856e559e20a3278536c26bcdca2283e9551b7eb420?d=identicon)[tieungao](/maintainers/tieungao)

---

Top Contributors

[![wize-wiz](https://avatars.githubusercontent.com/u/9093559?v=4)](https://github.com/wize-wiz "wize-wiz (36 commits)")[![michielkempen](https://avatars.githubusercontent.com/u/14795113?v=4)](https://github.com/michielkempen "michielkempen (12 commits)")[![mikaelpopowicz](https://avatars.githubusercontent.com/u/5689944?v=4)](https://github.com/mikaelpopowicz "mikaelpopowicz (6 commits)")[![milewski](https://avatars.githubusercontent.com/u/2874967?v=4)](https://github.com/milewski "milewski (6 commits)")[![ragingdave](https://avatars.githubusercontent.com/u/1168344?v=4)](https://github.com/ragingdave "ragingdave (5 commits)")[![tufankilicaslan](https://avatars.githubusercontent.com/u/701360?v=4)](https://github.com/tufankilicaslan "tufankilicaslan (3 commits)")[![almeidafranci](https://avatars.githubusercontent.com/u/9145755?v=4)](https://github.com/almeidafranci "almeidafranci (2 commits)")[![TheoKouzelis](https://avatars.githubusercontent.com/u/4980126?v=4)](https://github.com/TheoKouzelis "TheoKouzelis (2 commits)")[![yaroslawww](https://avatars.githubusercontent.com/u/23663794?v=4)](https://github.com/yaroslawww "yaroslawww (1 commits)")[![thienkimlove](https://avatars.githubusercontent.com/u/9207748?v=4)](https://github.com/thienkimlove "thienkimlove (1 commits)")[![niektenhoopen](https://avatars.githubusercontent.com/u/3450011?v=4)](https://github.com/niektenhoopen "niektenhoopen (1 commits)")[![bennofication](https://avatars.githubusercontent.com/u/7251115?v=4)](https://github.com/bennofication "bennofication (1 commits)")[![StanAngeloff](https://avatars.githubusercontent.com/u/93127?v=4)](https://github.com/StanAngeloff "StanAngeloff (1 commits)")

---

Tags

laravelnova

### Embed Badge

![Health badge](/badges/thienkimlove-nova-dependency-container/health.svg)

```
[![Health](https://phpackages.com/badges/thienkimlove-nova-dependency-container/health.svg)](https://phpackages.com/packages/thienkimlove-nova-dependency-container)
```

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