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

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

codicastudio/conditional
========================

A random Codica Studio package.

1.0.0(5y ago)05MITPHPPHP ^7.4 || ^8.0

Since Sep 25Pushed 5y ago1 watchersCompare

[ Source](https://github.com/codicastudio/conditional)[ Packagist](https://packagist.org/packages/codicastudio/conditional)[ Docs](https://github.com/codicastudio/conditional)[ RSS](/packages/codicastudio-conditional/feed)WikiDiscussions master Synced 3w ago

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

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

[](#conditional-container)

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

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

2097d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4a33b354bea681b74be49f37bbe9f3c4f145dbefe0f2b5cbb705b0731bf13fd3?d=identicon)[codicastudio](/maintainers/codicastudio)

### Embed Badge

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

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

###  Alternatives

[ph-7/qrcode-generator-php-class

Light QRCode PHP class (library). QR Code Generator using vCard 4.0 and the Google Chart AP

10415.7k2](/packages/ph-7-qrcode-generator-php-class)

PHPackages © 2026

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