PHP code example of dddeeemmmooonnn / nova-multicolumn-filter

1. Go to this page and download the library: Download dddeeemmmooonnn/nova-multicolumn-filter 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/ */

    

dddeeemmmooonnn / nova-multicolumn-filter example snippets


use dddeeemmmooonnn\NovaMulticolumnFilter\NovaMulticolumnFilter;

class UserFilter extends NovaMulticolumnFilter
{
    public $name = 'Filters';

    protected $columns = [
        // Simple text column declaration
        'column1' => '',
        
        // Customizing all
        'column2' => [
            'type' => 'email',
            'label' => 'E-mail',
            'operators' => [
                '=' => '=',
                //...
            ],
            'defaultOperator' => '=',
            'defaultValue' => '[email protected]',
            'preset' => true,
            'apply' => 'customApply',
            'placeholder' => 'input placeholder'
        ],
        
        // For checkboxes
        'column3' => [
            'type' => 'checkbox',
            'label' => 'Checkbox',
            'defaultValue' => 'anything', // Not empty = checked
        ],
        
        // Select type, options in array
        'column4' => [
            'type' => 'select',
            'label' => 'Select',
            'options' => [
                '1' => 'First',
                '2' => 'Second',
                //...
            ],
            'defaultValue' => '1',
        ],
        
        // Select type, options in optionsCustomOptions() method
        'column5' => [
            'type' => 'select',
            'label' => 'Select again',
            'options' => 'customOptions',
            'defaultValue' => '1',
        ],
        
        // operators in operatorsCustomOperators() method
        'column6' => [
            'type' => 'number',
            'label' => 'Number',
            'operators' => 'customOperators',
            'defaultValue' => '1',
        ],
        
        // Date type
        'column7' => [
            'type' => 'date',
            'label' => 'Date',
        ],
        
        // Using one db column in different declarations
        'column8' => [
            'type' => 'date',
            'label' => 'Date',
            'column' => 'column7',
        ],
    ];

    protected function operatorsCustomOperators()
    {
        return [
            '=' => 'Equals',
            '>' => 'Greater',
            '<' => 'Less',
        ];
    }

    protected function optionsCustomOptions()
    {
        return [
            '1' => 'One',
            '2' => 'Two',
            '3' => 'Three',
        ];
    }

    protected function applyCustomApply($query, $column, $operator, $value)
    {
        return $query->where($column, $operator, $value);
    }
    
    //Also you can override default values

    protected $default_column_type = 'text';
    
    protected $manual_update = false;
    
    protected function operatorsDefault()
    {
        return [
            '=' => '=',
            '>' => '>',
            '>=' => '>=',
            '<' => '<',
            '<=' => '<=',
            'LIKE' => 'Like',
        ];
    }
}