PHP code example of royduin / laravel-nova-field-dynamic-select

1. Go to this page and download the library: Download royduin/laravel-nova-field-dynamic-select 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/ */

    

royduin / laravel-nova-field-dynamic-select example snippets


public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        DynamicSelect::make('Country', 'country')
            ->options(['US' => 'United States', 'UK' => 'United Kingdom'])
            ->rules('     ])
        ,

        DynamicSelect::make('Provider', 'provider')
            ->options(['PR' => 'Premium', 'ST' => 'Standard'])
            ->rules(' ['A' => 'Fast shipping', 'B' => 'Normal shipping'];
                }
            })
            ->default(function ($values) {
                if (! $values) {
                    return null;
                }
                if ($values['country'] === 'UK') {
                    return [
                        'label' => 'Normal shipping',
                        'value' => 'B'
                    ];
                }
            })
            ->rules('

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        DynamicSelect::make('Country', 'country')
            ->forAction(self::class)
            ->options(['US' => 'United States', 'UK' => 'United Kingdom'])
            ->rules('orAction(self::class)
            ->dependsOn(['country', 'provider'])
            ->options(function($values) { 
                if($values['country'] === 'UK' && $values['provider'] === 'PR') {
                    return ['A' => 'Fast shipping', 'B' => 'Normal shipping', 'C' => 'Free shipping'];
                } else {
                    return ['A' => 'Fast shipping', 'B' => 'Normal shipping'];
                }
            })
            ->rules('