PHP code example of kingmaker / filament-filter-sets

1. Go to this page and download the library: Download kingmaker/filament-filter-sets 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/ */

    

kingmaker / filament-filter-sets example snippets


use Filament\Tables\Table;
use Filament\Tables\Filters\TernaryFilter;
use Kingmaker\Filament\FilterSets\FilterSet;

public function table(Table $table): Table
{
    return $table
        ->filters([
            TernaryFilter::make('is_published'),
            // ...
        ])
        ->filterSets([
            FilterSet::make('unread_quick_reads')
                ->label('Unread Quick Reads')
                ->icon('heroicon-o-rocket-launch')
                ->filters([
                    'is_read' => ['value' => false],
                    'read_time' => ['read_time_range' => 'quick'],
                ]),

            FilterSet::make('loved_stories')
                ->icon('heroicon-s-heart')
                ->color('danger')
                ->filters([
                    'min_rating' => ['rating_clause' => 'greater_equal', 'rating_value' => 4],
                ]),
        ]);
}

FilterSet::make('my_drafts')
    ->filters(fn (): array => [
        'author' => ['value' => auth()->id()],
        'is_published' => ['value' => false],
    ]),

Livewire::test(ListStories::class)
    ->call('applyTableFilterSet', 'loved_stories')
    ->assertCanSeeTableRecords([$lovedStory])
    ->assertCanNotSeeTableRecords([$mediocreStory]);