PHPackages                             kayacekovic/conditional-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. kayacekovic/conditional-container

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

kayacekovic/conditional-container
=================================

Provides an easy way to conditionally show and hide fields in your Nova resources.

01.7kPHP

Since Nov 14Pushed 3y agoCompare

[ Source](https://github.com/kayacekovic/conditional-container)[ Packagist](https://packagist.org/packages/kayacekovic/conditional-container)[ RSS](/packages/kayacekovic-conditional-container/feed)WikiDiscussions development Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Conditional Container
=====================

[](#conditional-container)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7338928467e5d92d490422ff22b67d4f0dd34ce27b54e6aca9bbb4e033cb8cbf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6469676974616c2d63726561746976652f636f6e646974696f6e616c2d636f6e7461696e6572)](https://packagist.org/packages/digital-creative/conditional-container)[![Total Downloads](https://camo.githubusercontent.com/3937f5c20f2b42099c4811a45ad4d24710398ad430566088d2c7af3016309a13/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6469676974616c2d63726561746976652f636f6e646974696f6e616c2d636f6e7461696e6572)](https://packagist.org/packages/digital-creative/conditional-container)[![License](https://camo.githubusercontent.com/1dc3eb92a721115df4979a08e73e0a9f58ec95e20dd804dbf719ce069c308cb0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6469676974616c2d63726561746976652f636f6e646974696f6e616c2d636f6e7461696e6572)](https://github.com/dcasia/conditional-container/blob/master/LICENSE)

[![Laravel Nova Conditional Container in action](https://raw.githubusercontent.com/dcasia/conditional-container/master/demo.gif)](https://raw.githubusercontent.com/dcasia/conditional-container/master/demo.gif)

Provides an easy way to conditionally show and hide fields in your Nova resources.

Installation
============

[](#installation)

You can install the package via composer:

```
composer require digital-creative/conditional-container

```

Usage
-----

[](#usage)

Basic demo showing the power of this field:

```
use DigitalCreative\ConditionalContainer\ConditionalContainer;
use DigitalCreative\ConditionalContainer\HasConditionalContainer;

class ExampleNovaResource extends Resource {

    use HasConditionalContainer; // Important!!

    public function fields(Request $request)
    {
        return [

            Select::make('Option', 'option')
                  ->options([
                      1 => 'Option 1',
                      2 => 'Option 2',
                      3 => 'Option 3',
                  ]),

            Text::make('Content', 'content')->rules('required'),

            /**
             * Only show field Text::make('Field A') if the value of option is equals 1
             */
            ConditionalContainer::make([ Text::make('Field A') ])
                                ->if('option = 1'),

            /**
             * Equivalent to: if($option === 2 && $content === 'hello world')
             */
            ConditionalContainer::make([ Text::make('Field B') ])
                                ->if('option = 2 AND content = "hello world"'),

            /**
             * Equivalent to: if(($option !== 2 && $content > 10) || $option === 3)
             */
            ConditionalContainer::make([ Text::make('Field C')->rules('required') ])
                                ->if('(option != 2 AND content > 10) OR option = 3'),

            /**
             * Example with Validation and nested ConditionalContainer!
             * Equivalent to: if($option === 3 || $content === 'demo')
             */
            ConditionalContainer::make([

                                    Text::make('Field D')->rules('required') // Yeah! validation works flawlessly!!

                                    ConditionalContainer::make([ Text::make('Field E') ])
                                                        ->if('field_d = Nice!')

                                ])
                                ->if('option = 3 OR content = demo')
        ];
    }

}
```

The `->if()` method takes a single expression argument that follows this format:

```
(attribute COMPARATOR value) OPERATOR ...so on

```

you can build any complex logical operation by wrapping your condition in `()` examples:

```
ConditionalContainer::make(...)->if('first_name = John');
ConditionalContainer::make(...)->if('(first_name = John AND last_name = Doe) OR (first_name = foo AND NOT last_name = bar)');
ConditionalContainer::make(...)->if('first_name = John AND last_name = Doe');
```

you can chain multiple `->if()` together to group your expressions by concern, example:

```
ConditionalContainer::make(...)
                    //->useAndOperator()
                    ->if('age > 18 AND gender = male')
                    ->if('A contains "some word"')
                    ->if('B contains "another word"');
```

by default the operation applied on each `->if()` will be `OR`, therefore if any of the if methods evaluates to true the whole operation will be considered truthy, if you want to execute an `AND` operation instead append `->useAndOperator()` to the chain

### Currently supported operators:

[](#currently-supported-operators)

- AND
- OR
- NOT
- XOR
- and parentheses

### Currently supported comparators:

[](#currently-supported-comparators)

ComparatorDescription&gt;Greater than&lt;Less than&lt;=Less than or equal to&gt;=Greater than or equal to==Equal===Identical!=Not equal!==Not Identicaltruthy / booleanValidate against truthy valuescontains / includesCheck if input contains certain valuestartsWithCheck if input starts with certain valueendsWithCheck if input ends with certain value#### Examples

[](#examples)

- Display field only if user has selected file

```
[
    Image::make('Image'),
    ConditionalContainer::make([ Text::make('caption')->rules('required') ])
                        ->if('image truthy true'),
]
```

- Display extra fields only if selected morph relation is of type Image or Video

```
[
    MorphTo::make('Resource Type', 'fileable')->types([
        App\Nova\Image::class,
        App\Nova\Video::class,
        App\Nova\File::class,
    ]),

    ConditionalContainer::make([ Image::make('thumbnail')->rules('required') ])
                        ->if(function () {
                            return 'fileable = ' . App\Nova\Image::uriKey();
                        })
                        ->if(function () {
                            return 'fileable = ' . App\Nova\Video::uriKey();
                        })
]
```

- Display inline HTML only if `Reason` field is empty, show extra fields otherwise.

```
[
    Trix::make('Reason'),

    ConditionalContainer::make([ Text::make('Extra Information')->rules('required') ])
                        ->if('reason truthy true'),

    ConditionalContainer::make([
                            Heading::make('Please write a good reason...')->asHtml()
                        ])
                        ->if('reason truthy false'),
]
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://raw.githubusercontent.com/dcasia/conditional-container/master/LICENSE) for more information.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 Bus Factor1

Top contributor holds 72.5% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8a728b47a1ee9fd11f949888a6de60971bbeaf3057d022eab6a6e50491089b4b?d=identicon)[kayacekovic](/maintainers/kayacekovic)

---

Top Contributors

[![milewski](https://avatars.githubusercontent.com/u/2874967?v=4)](https://github.com/milewski "milewski (37 commits)")[![kayacekovic](https://avatars.githubusercontent.com/u/32109756?v=4)](https://github.com/kayacekovic "kayacekovic (4 commits)")[![bolechen](https://avatars.githubusercontent.com/u/195015?v=4)](https://github.com/bolechen "bolechen (2 commits)")[![Israel5](https://avatars.githubusercontent.com/u/63180786?v=4)](https://github.com/Israel5 "Israel5 (1 commits)")[![mennotempelaar](https://avatars.githubusercontent.com/u/6905655?v=4)](https://github.com/mennotempelaar "mennotempelaar (1 commits)")[![nw-b](https://avatars.githubusercontent.com/u/1254417?v=4)](https://github.com/nw-b "nw-b (1 commits)")[![Sjoertjuh](https://avatars.githubusercontent.com/u/63722509?v=4)](https://github.com/Sjoertjuh "Sjoertjuh (1 commits)")[![squarebeard](https://avatars.githubusercontent.com/u/175705892?v=4)](https://github.com/squarebeard "squarebeard (1 commits)")[![timcv](https://avatars.githubusercontent.com/u/1415514?v=4)](https://github.com/timcv "timcv (1 commits)")[![dnwjn](https://avatars.githubusercontent.com/u/57711725?v=4)](https://github.com/dnwjn "dnwjn (1 commits)")[![dormadekhin](https://avatars.githubusercontent.com/u/32381310?v=4)](https://github.com/dormadekhin "dormadekhin (1 commits)")

### Embed Badge

![Health badge](/badges/kayacekovic-conditional-container/health.svg)

```
[![Health](https://phpackages.com/badges/kayacekovic-conditional-container/health.svg)](https://phpackages.com/packages/kayacekovic-conditional-container)
```

PHPackages © 2026

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