PHP code example of thiktak / filament-sql-nested-builder-form

1. Go to this page and download the library: Download thiktak/filament-sql-nested-builder-form 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/ */

    

thiktak / filament-sql-nested-builder-form example snippets


// use App\Models\User;
use Thiktak\FilamentNestedBuilderForm\Forms\Components\NestedBuilder;
use Thiktak\FilamentNestedBuilderForm\Forms\Components\NestedSubBuilder;
use Thiktak\FilamentSQLNestedBuilderForm\Forms\Components\SQLNestedBuilder;

    public static function form(Form $form): Form
    {
        return $form
            ->schema([

                Section::make('Nested Builder Form')
                    ->description('Example of the SQL Nested Builder Form (SQL Query)')
                    ->schema([
                        // configuration is an Array
                        SQLNestedBuilder::make('configuration')

                            // nestedConfiguration apply this set up to all children
                            ->nestedConfiguration(function (NestedSubBuilder $builder, NestedBuilder $parent) {
                                // import default configuration of this package
                                $parent->defaultNestedConfiguration($builder);
                            })

                            // Display the first Hint as a Raw SQL query of User Model
                            ->hint(function (?array $state) {
                                return SQLNestedBuilder::getFullyLinearizedArrayToEloquent($state, User::query())
                                    ->getQuery()
                                    ->toRawSql()
                                ;
                            })
                    ]),
            ]);
    }

    SQLNestedBuilder::make('configuration')

        ->nestedConfiguration(function (NestedSubBuilder $builder, NestedBuilder $parent) {
            // import default configuration of this package
            $parent->defaultNestedConfiguration($builder);

            // Change the TextInput -> Select
            $parent->fieldComponent(
                fn () => Select::make('field')
                    ->options([
                        'id'    => 'User Id',
                        'email' => 'User email',
                    ])
                    ->searchable()
            );
        })

SQLNestedBuilder::getFullyLinearizedArrayToEloquent($state, User::query())
    ->getQuery()
    ->toRawSql()

  SQLNestedBuilder::getFullyLinearizedArrayToSQL(?array $state); // If consume the whole array

  SQLNestedBuilder::getFullyLinearizedArrayToSQL(?array $state, 'group'); // if level of group
  SQLNestedBuilder::getFullyLinearizedArrayToSQL(?array $state, 'rule'); // if level of rule