PHP code example of madzee-m / moonshine-tom-select

1. Go to this page and download the library: Download madzee-m/moonshine-tom-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/ */

    

madzee-m / moonshine-tom-select example snippets


use MadZeeM\MoonshineTomSelect\Fields\TomSelect;


TomSelect::make('Select')

use MadZeeM\MoonshineTomSelect\Fields\TomSelectBelongsTo;
use MadZeeM\MoonshineTomSelect\Fields\TomSelectBelongsToMany;

TomSelectBelongs::make('Select')
TomSelectBelongsToMany::make('Select')

addPlugins(array|string $plugin, array $pluginOptions = [])

TomSelect::make('Select')
    ->addPlugins('checkbox_options', [...])
    
TomSelect::make('Select')
    ->addPlugins(['checkbox_options', '...'])
    
TomSelect::make('Select')
    ->addPlugins([
        'checkbox_options' => [...]
    ])

TomSelect::make('Select')
    ->addPlugins('myPlugin', [
        'foo' => 'bar'
    ])

settings(array $settings)

TomSelect::make('Select')
    ->settings([
        'maxOptions' => 100,
        'maxItems' => 100,
        'hideSelected' => false
    ])

fieldNames(
    ?string $valueField = null,         // default: value
    ?string $labelField = null,         // default: label
    ?string $descriptionField = null,   // default: description

    ?string $childrenField = null,      // default: values
    ?string $optgroupValueField = null, // default: value
    ?string $optgroupLabelField = null, // default: label
    ?string $optgroupField = null,      // default: optgroup

    ?array $searchField = null,         // default: ['label']
    ?string $disabledField = null,      // default: disabled
    ?string $sortField = null           // default: $order
)

TomSelect::make('Select')
    ->fieldNames(
        valueField: 'id',
        labelField: 'name',
        childrenField: 'children',
    )

asyncSettings(array $settings)

TomSelect::make('Select')
    ->asyncSettings([
        // Можно менять название поля поиска
        'queryKey' => 'query',
        
        // Можно отправить текущие активные значения, просто указываем название 
        'selectedValuesKey' => '_value',
        
        // Если результат обвернуть например в data, то указываем этот ключ
        'resultKey' => 'data',
        
        // Если хотите, чтобы вместе с запросом, шли все поля текущей формы, то задаем TRUE
        'withAllFields' => false,
    ])

asyncOnInit(bool $whenOpen = true, bool $withLoading = false)

TomSelect::make('Select')
    ->asyncOnInit(withLoading: true)

> TomSelect::make('Select')
>   ->multiple()
>   ->withoutSearchable()
>