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

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

outl1ne/nova-dependency-container
=================================

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

2.0.4(2y ago)628.2k↓46%6MITPHPPHP &gt;=8.0

Since Sep 7Pushed 2y ago2 watchersCompare

[ Source](https://github.com/outl1ne/nova-dependency-container)[ Packagist](https://packagist.org/packages/outl1ne/nova-dependency-container)[ RSS](/packages/outl1ne-nova-dependency-container/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (1)Versions (9)Used By (0)

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

[](#nova-dependency-container)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7a070f9d5c8ac9ad9ac55b39f12a87e90683007898b17d62ea7df446fb0957ff/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f75746c316e652f6e6f76612d646570656e64656e63792d636f6e7461696e65722e737667)](https://packagist.org/packages/outl1ne/nova-dependency-container)[![Total Downloads](https://camo.githubusercontent.com/77f7fbe1a34f8e539563ccdcff03c612ef662ec7174d994a00daddec311d18f1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f75746c316e652f6e6f76612d646570656e64656e63792d636f6e7461696e65722e737667)](https://packagist.org/packages/outl1ne/nova-dependency-container)[![License](https://camo.githubusercontent.com/3f8b3166d2d79dc9303c4487b09df220ed23ebc8cf91e28fbe14ffd5ad4ca2fc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6f75746c316e652f6e6f76612d646570656e64656e63792d636f6e7461696e65722e737667)](https://github.com/outl1ne/nova-dependency-container/blob/master/LICENSE.md)

This [Laravel Nova](https://nova.laravel.com) package adds a container for grouping fields that depend on other fields' values.

Requirements
------------

[](#requirements)

- `php: >=8.0`
- `laravel/nova: ^4.0`

Screenshots
-----------

[](#screenshots)

[![Screenshots](./docs/demo.gif)](./docs/demo.gif)

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

[](#installation)

Install the package in a Laravel Nova project via Composer:

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

Usage
-----

[](#usage)

1. Add the `Outl1ne\DependencyContainer\HasDependencies` trait to your Nova Resource.
2. Add the `Outl1ne\DependencyContainer\DependencyContainer` field to your Nova Resource.
3. Add the `Outl1ne\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),

        ];
    }
}
```

### 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 `DependencyContainer`:

```
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](./docs/demo-2.gif)](./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')
```

License
-------

[](#license)

This project is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor3

3 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 ~114 days

Recently: every ~84 days

Total

7

Last Release

1030d ago

Major Versions

1.0.1 → 2.0.02022-08-19

PHP version history (2 changes)1.0.0PHP &gt;=7.2.0

2.0.0PHP &gt;=8.0

### Community

Maintainers

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

---

Top Contributors

[![wize-wiz](https://avatars.githubusercontent.com/u/9093559?v=4)](https://github.com/wize-wiz "wize-wiz (36 commits)")[![Tarpsvo](https://avatars.githubusercontent.com/u/2018660?v=4)](https://github.com/Tarpsvo "Tarpsvo (26 commits)")[![ragingdave](https://avatars.githubusercontent.com/u/1168344?v=4)](https://github.com/ragingdave "ragingdave (21 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)")[![KasparRosin](https://avatars.githubusercontent.com/u/33309407?v=4)](https://github.com/KasparRosin "KasparRosin (3 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)")[![sash](https://avatars.githubusercontent.com/u/45210?v=4)](https://github.com/sash "sash (1 commits)")[![StanAngeloff](https://avatars.githubusercontent.com/u/93127?v=4)](https://github.com/StanAngeloff "StanAngeloff (1 commits)")[![niektenhoopen](https://avatars.githubusercontent.com/u/3450011?v=4)](https://github.com/niektenhoopen "niektenhoopen (1 commits)")[![yaroslawww](https://avatars.githubusercontent.com/u/23663794?v=4)](https://github.com/yaroslawww "yaroslawww (1 commits)")[![dododedodonl](https://avatars.githubusercontent.com/u/100052?v=4)](https://github.com/dododedodonl "dododedodonl (1 commits)")[![vkazakevich](https://avatars.githubusercontent.com/u/9676524?v=4)](https://github.com/vkazakevich "vkazakevich (1 commits)")[![wesdeboer](https://avatars.githubusercontent.com/u/901355?v=4)](https://github.com/wesdeboer "wesdeboer (1 commits)")[![bennofication](https://avatars.githubusercontent.com/u/7251115?v=4)](https://github.com/bennofication "bennofication (1 commits)")[![priithansen](https://avatars.githubusercontent.com/u/1476082?v=4)](https://github.com/priithansen "priithansen (1 commits)")

---

Tags

laravelnova

### Embed Badge

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

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

###  Alternatives

[optimistdigital/nova-sortable

This Laravel Nova package allows you to reorder models in a Nova resource's index view using drag &amp; drop.

2872.1M6](/packages/optimistdigital-nova-sortable)[outl1ne/nova-sortable

This Laravel Nova package allows you to reorder models in a Nova resource's index view using drag &amp; drop.

2861.8M9](/packages/outl1ne-nova-sortable)[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)[sbine/route-viewer

A Laravel Nova tool to view your registered routes.

57215.9k](/packages/sbine-route-viewer)[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

14720.0k](/packages/markwalet-nova-modal-response)

PHPackages © 2026

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