Beartropy Tables
Defining Filters
Return an array of Filter instances from the filters() method to enable column-level filtering.
Basic Setup
[Filter]::make(string $label, ?string $column) — If only the label is provided, the filter matches against the column with the same label. Use the second parameter to target a specific column.
1public function filters(): array {2 return [3 FilterString::make('name'),4 FilterDateRange::make('Created At')5 ];6}
Filters vs Global Search
Filter Types
Built-in filter classes for common data patterns.
FilterString
FilterString::make(string $label, ?string $column) — A text input filter that performs a LIKE search on the target column.
1FilterString::make('name') // Searches column with label 'name'2 3FilterString::make('Edad', 'age') // Searches column with label 'age'
FilterDateRange
FilterDateRange::make(string $label, ?string $column) — Displays a date range picker (using flatpickr) and filters rows within the selected range.
1FilterDateRange::make('created_at')
FilterSelect
FilterSelect::make(string $label, array $options) — Displays a dropdown with the provided options for exact-match filtering.
1FilterSelect::make('type', ["primary", "secondary"])
FilterSelectMagic
FilterSelectMagic::make(string $label) — Automatically extracts unique values from the column data and displays them as dropdown options. No manual option list needed.
1[2 ["id"=>1, "color"=>"red", "type"=>"Primary"],3 ["id"=>2, "color"=>"violet", "type"=>"Secondary"],4 ["id"=>2, "color"=>"green", "type"=>"Primary"],5]6 7FilterSelectMagic::make('type')8// Will display Primary and Secondary in the <select>
FilterBool
FilterBool::make(string $label, ?string $column) — Adds a true/false toggle filter for boolean columns.
1FilterBool::make('isprimary')
Custom Filter Logic
Override default filtering behavior with query callbacks for complex scenarios.
Custom Query Callback
->query(callable $callback) — Define custom query logic for any filter. This replaces the default filtering behavior, giving you full control. The callback receives $query, $value, and $filter.
1FilterString::make('Theme', 'theme_setting')->query(function($query, $value, $filter) {2 // $value is the user input3 $query->whereHas('settings', function($q) use ($value) {4 $q->where('key', 'theme')->where('value', 'like', "%$value%");5 });6});
Use query() for relationship filtering
query() callback is essential for filtering on related models. Use whereHas() inside the callback to filter by HasMany, BelongsTo, or other relationship values.
Complete Example
A playground table demonstrating all filter types working together.
FilteredUsersTable.php
This example combines FilterString, FilterSelect with a custom query, FilterBool with null-check logic, FilterDateRange, and a multi-field text filter.
1use App\Models\Plataforma; 2use App\Models\User; 3use Beartropy\Tables\Classes\Columns\Column; 4use Beartropy\Tables\Classes\Columns\DateColumn; 5use Beartropy\Tables\Classes\Filters\FilterBool; 6use Beartropy\Tables\Classes\Filters\FilterDateRange; 7use Beartropy\Tables\Classes\Filters\FilterSelect; 8use Beartropy\Tables\Classes\Filters\FilterString; 9use Beartropy\Tables\YATBaseTable;10 11class FilteredUsersTable extends YATBaseTable12{13 public $model = User::class;14 15 public array $with = ['plataforma'];16 17 public function columns(): array18 {19 return [20 Column::make('Name', 'name')->sortable()->searchable(),21 Column::make('Email', 'email')->sortable()->searchable(),22 Column::make('Platform', 'plataforma.name')23 ->sortable(false)->searchable(false),24 DateColumn::make('Created', 'created_at')25 ->outputFormat('M d, Y'),26 ];27 }28 29 public function filters(): array30 {31 $plataformas = Plataforma::pluck('name', 'id')->toArray();32 33 return [34 FilterString::make('Name', 'name'),35 36 FilterSelect::make('Platform', $plataformas)37 ->query(function ($query, $value) {38 $query->whereHas('plataforma', function ($q) use ($value) {39 $q->where('id', $value);40 });41 }),42 43 FilterBool::make('Verified', null, 'email_verified_at')44 ->query(function ($query, $value) {45 if ($value === 'true') {46 $query->whereNotNull('email_verified_at');47 } else {48 $query->whereNull('email_verified_at');49 }50 }),51 52 FilterDateRange::make('Created', 'created_at'),53 54 FilterString::make('Name or Email')55 ->query(function ($query, $value) {56 $query->where(function ($q) use ($value) {57 $q->where('name', 'like', "%{$value}%")58 ->orWhere('email', 'like', "%{$value}%");59 });60 }),61 ];62 }63 64 public function settings(): void65 {66 $this->setPerPageDefault(15);67 }68}
Live Demo
Try it — use the filters to narrow down the table data interactively.
Filtered Table
| # |
Name
|
Department
|
Active
|
Hired
|
|---|---|---|---|---|
| 1 | Alice Johnson | Engineering | Yes | Jan 15, 2023 |
| 2 | Bob Smith | Marketing | Yes | Mar 20, 2023 |
| 3 | Carol White | Engineering | No | May 10, 2023 |
| 4 | David Brown | Sales | Yes | Jul 05, 2023 |
| 5 | Eva Martinez | Marketing | No | Sep 22, 2023 |
| 6 | Frank Lee | Engineering | Yes | Jan 18, 2024 |
| 7 | Grace Kim | Sales | Yes | Mar 03, 2024 |
| 8 | Henry Davis | Marketing | Yes | May 29, 2024 |
| 9 | Ivy Chen | Engineering | No | Jul 14, 2024 |
| 10 | Jack Wilson | Sales | Yes | Sep 01, 2024 |
1<livewire:tables.demos.demo-filters-table />