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

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

mlsolutions/nova-dependency-container
=====================================

A Laravel Nova 4 form container for grouping fields that depend on other field values.

1.3.0(8mo ago)01.5k↓44.3%MITPHPPHP ^8.0

Since Jun 26Pushed 8mo agoCompare

[ Source](https://github.com/ml-solutions-ltda/nova-dependency-container)[ Packagist](https://packagist.org/packages/mlsolutions/nova-dependency-container)[ Fund](https://www.paypal.com/donate/?hosted_button_id=LHJQRG9FXSYCU)[ RSS](/packages/mlsolutions-nova-dependency-container/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (2)Versions (17)Used By (0)

nova 5 dependency container
===========================

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

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

Features:

- working form validation inside unlimited nested containers
- support of ebess/advanced-nova-media-library

This plugin is based on [ml-solutions-ltda/nova-dependency-container](https://github.com/ml-solutions-ltda/nova-dependency-container)and only supports **Nova 5.x** and **PHP 8.x**.

Demo
----

[](#demo)

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

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

[](#installation)

The package can be installed through Composer.

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

Usage
-----

[](#usage)

1. Add the `MlSolutions\DependencyContainer\HasDependencies` trait to your Nova Resource.
2. Add the `MlSolutions\DependencyContainer\DependencyContainer` to your Nova Resource `fields()` method.
3. Add the `MlSolutions\DependencyContainer\ActionHasDependencies` trait to your Nova Actions that you wish to use dependencies on.

```
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(),

            DependencyContainer::make([
                Text::make('First Name', 'first_name')
            ])->dependsOn('name_format', 0),
        ];
    }
}
```

Available dependencies
----------------------

[](#available-dependencies)

The package supports these kinds of dependencies:

1. `->dependsOn('field', 'value')`
2. `->dependsOnNot('field', 'value')`
3. `->dependsOnEmpty('field')`
4. `->dependsOnNotEmpty('field')`
5. `->dependsOnNullOrZero('field')`
6. `->dependsOnIn('field', [array])`
7. `->dependsOnNotIn('field', [array])`

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

```
DependencyContainer::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/mlsolutions/nova-dependency-container/master/docs/demo-2.gif)](https://raw.githubusercontent.com/mlsolutions/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'),

DependencyContainer::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 [
			DependencyContainer::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 [
		DependencyContainer::make([
		    // pivot field rules_all
		    Select::make('Type', 'type_1')
		    	->options([
		    		/* some options */
	    		])
		    	->displayUsingLabels()
		])
		->dependsOn('role_user', 1),

		DependencyContainer::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,
]),

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

Workaround for index or details page
------------------------------------

[](#workaround-for-index-or-details-page)

Use the field within resource methods `fieldsForCreate` or `fieldsForUpdate`:

```
DependencyContainer::make([
    Select::make('Parent name', 'parent_id')
        ->options(...)
])->dependsOn('code', 'column'),
```

To display some values on index or details page, use any field you like to display the value within resource methods `fieldsForIndex` or `fieldsForDetail`:

```
Select::make('Parent name', 'parent_id')
        ->options(...),

// OR

Text::make('Parent name', 'parent_id'),
```

License
-------

[](#license)

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

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance60

Regular maintenance activity

Popularity20

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

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

Total

16

Last Release

253d ago

### Community

Maintainers

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

---

Top Contributors

[![alexwenzel](https://avatars.githubusercontent.com/u/3659928?v=4)](https://github.com/alexwenzel "alexwenzel (20 commits)")[![EslanaRegina](https://avatars.githubusercontent.com/u/134294881?v=4)](https://github.com/EslanaRegina "EslanaRegina (4 commits)")[![ali-raza-saleem](https://avatars.githubusercontent.com/u/88083032?v=4)](https://github.com/ali-raza-saleem "ali-raza-saleem (2 commits)")[![luissobrinho](https://avatars.githubusercontent.com/u/17295212?v=4)](https://github.com/luissobrinho "luissobrinho (2 commits)")[![friendlyhomosapien](https://avatars.githubusercontent.com/u/81475921?v=4)](https://github.com/friendlyhomosapien "friendlyhomosapien (1 commits)")[![okaufmann](https://avatars.githubusercontent.com/u/4414498?v=4)](https://github.com/okaufmann "okaufmann (1 commits)")

---

Tags

laravelfieldnovanova-4

### Embed Badge

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

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

###  Alternatives

[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17818.7k](/packages/markwalet-nova-modal-response)[ebess/advanced-nova-media-library

Laravel Nova tools for managing the Spatie media library.

6143.5M22](/packages/ebess-advanced-nova-media-library)[alexwenzel/nova-dependency-container

A Laravel Nova 4 form container for grouping fields that depend on other field values.

461.1M2](/packages/alexwenzel-nova-dependency-container)[sbine/route-viewer

A Laravel Nova tool to view your registered routes.

57239.7k](/packages/sbine-route-viewer)[novius/laravel-nova-order-nestedset-field

A Laravel Nova field that make your resources orderable

2391.9k2](/packages/novius-laravel-nova-order-nestedset-field)[ferdiunal/nova-editable-field

A Laravel Nova package to make fields editable.

115.3k](/packages/ferdiunal-nova-editable-field)

PHPackages © 2026

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