PHP code example of and48 / table-filters
1. Go to this page and download the library: Download and48/table-filters 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/ */
and48 / table-filters example snippets
use AND48\TableFilters\Models\Filter;
...
User::addTableFilters([
['field' =>'id', 'type' => Filter::TYPE_NUMBER, 'caption' => 'ID'],
['field' =>'name', 'type' => Filter::TYPE_STRING, 'caption' => 'Name'],
['field' =>'birthday', 'type' => Filter::TYPE_DATE, 'caption' => 'Birthday'],
['field' =>'is_blocked', 'type' => Filter::TYPE_BOOLEAN, 'caption' => 'Is blocked'],
['field' =>'balance', 'type' => Filter::TYPE_NUMBER, 'caption' => 'Balance'],
['field' =>'status', 'type' => Filter::TYPE_ENUM, 'caption' => 'Status'],
['field' =>'parent_id', 'type' => Filter::TYPE_SOURCE, 'caption' => 'Parent user'],
]);
...
}
$filters = User::tableFilterList(true, [
'status' => ['new', 'verified', 'active', 'suspended']]);
$filter = Filter::find($filter_id);
$source_data = $filter->sourceData($page, $search_query);
route('filters.source_data', ['filter_id' => 1, 'query' => '*', 'page' => 2]);
$filters = [
['id' => 1, 'operator' => '!=', 'values' => [2, 3]],
['id' => 2, 'operator' => '~', 'values' => ['and', 'dy']],
['id' => 3, 'operator' => '>=', 'values' => ['1986-06-06']],
['id' => 4, 'operator' => '=', 'values' => [false]],
['id' => 6, 'operator' => '=', 'values' => ['new', 'verified']],
['id' => 7, 'operator' => '!=', 'values' => []],
];
$users = User::tableFilter($filters)->get();
sh
php artisan vendor:publish --provider="AND48\TableFilters\TableFiltersServiceProvider" --tag="migrations"
sh
php artisan migrate
sh
php artisan vendor:publish --provider="AND48\TableFilters\TableFiltersServiceProvider" --tag="config"