PHP code example of codicastudio / conditional

1. Go to this page and download the library: Download codicastudio/conditional library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codicastudio / conditional example snippets



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(' 2 && $content > 10) || $option === 3)
             */
            ConditionalContainer::make([ Text::make('Field C')->rules('   ])
                                ->if('option = 3 OR content = demo')
        ];
    }

}

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');

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

[
    Image::make('Image'),
    ConditionalContainer::make([ Text::make('caption')->rules('

[
    MorphTo::make('Resource Type', 'fileable')->types([
        App\Nova\Image::class,
        App\Nova\Video::class,
        App\Nova\File::class,
    ]),
    
    ConditionalContainer::make([ Image::make('thumbnail')->rules('leable = ' . App\Nova\Video::uriKey();
                        })
]

[
    Trix::make('Reason'),
    
    ConditionalContainer::make([ Text::make('Extra Information')->rules('             Heading::make('<p class="text-danger">Please write a good reason...</p>')->asHtml()
                        ])
                        ->if('reason truthy false'),
]