laratribe/laravel-advanced-filters v1.0.0 · 80 products ·
no page reload — the panel dispatches, the table re-queries
Select column
| Name | SKU | Category | Status | Price | Stock | Released |
|---|---|---|---|---|---|---|
| Quartz Lite 31 | SKU-0031 | Toys | Low | 119.20 | 123 | 17 Oct 2025 |
| Nimbus Pro 32 | SKU-0032 | Electronics | Out | 122.90 | 136 | 6 Oct 2025 |
| Vertex Mini 33 | SKU-0033 | Books | In stock | 126.60 | 9 | 25 Sep 2025 |
| Lumen Max 34 | SKU-0034 | Clothing | Low | 130.30 | 22 | 14 Sep 2025 |
| Atlas Lite 35 | — | Toys | Out | 134.00 | 35 | 3 Sep 2025 |
| Orbit Pro 36 | SKU-0036 | Electronics | In stock | 137.70 | 48 | 23 Aug 2025 |
| Cobalt Mini 37 | SKU-0037 | Books | Low | 141.40 | 61 | 16 Sep 2026 |
| Ember Max 38 | SKU-0038 | Clothing | Out | 145.10 | 74 | 5 Sep 2026 |
| Quartz Lite 39 | SKU-0039 | Toys | In stock | 148.80 | 87 | 25 Aug 2026 |
| Nimbus Pro 40 | SKU-0040 | Electronics | Low | 152.50 | 100 | 14 Aug 2026 |
| Vertex Mini 41 | SKU-0041 | Books | Out | 156.20 | 113 | 3 Aug 2026 |
| Lumen Max 42 | — | Clothing | In stock | 159.90 | 126 | 23 Jul 2026 |
| Atlas Lite 43 | SKU-0043 | Toys | Low | 163.60 | 139 | 12 Jul 2026 |
| Orbit Pro 44 | SKU-0044 | Electronics | Out | 167.30 | 12 | 1 Jul 2026 |
| Cobalt Mini 45 | SKU-0045 | Books | In stock | 171.00 | 25 | 20 Jun 2026 |
Same model as the Blade page — not a line of filter logic changes. The panel dispatches an event; the results component listens and re-queries.
app/Models/Product.php
identical on all three pages <?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Laratribe\AdvancedFilters\Concerns\HasFilters;
use Laratribe\AdvancedFilters\Contracts\Filterable;
use Laratribe\AdvancedFilters\Filters\{DateFilter, NumericFilter, SetFilter, TextFilter};
class Product extends Model implements Filterable
{
use HasFilters;
protected $guarded = [];
public $timestamps = false;
protected function casts(): array
{
return ['price' => 'float', 'stock' => 'integer', 'released_at' => 'date'];
}
/**
* The one place that decides what can be filtered — and therefore the allow-list.
* Anything not declared here can never reach the query, whatever the request says.
*/
public static function filters(): array
{
return [
TextFilter::make('name', 'Name'),
TextFilter::make('sku', 'SKU')->nullable(),
SetFilter::make('category', 'Category')
->options([
'electronics' => 'Electronics',
'books' => 'Books',
'clothing' => 'Clothing',
'toys' => 'Toys',
])
->multiple(),
SetFilter::make('status', 'Status')->options([
'in_stock' => 'In stock',
'low' => 'Low stock',
'out' => 'Out of stock',
]),
NumericFilter::make('price', 'Price'),
NumericFilter::make('stock', 'Stock'),
DateFilter::make('released_at', 'Released'),
];
}
}
app/Livewire/ProductResults.php
listens for the event <?php
namespace App\Livewire;
use App\Models\Product;
use Laratribe\AdvancedFilters\Support\FilteredQuery;
use Livewire\Attributes\On;
use Livewire\Component;
use Livewire\WithPagination;
/**
* The event-driven integration: the package's panel owns the filter rows and dispatches
* `advanced-filters-updated`; this component listens and re-queries. The two know nothing
* about each other.
*/
class ProductResults extends Component
{
use WithPagination;
/** @var array<int, array<string, mixed>> */
public array $filters = [];
#[On('advanced-filters-updated')]
public function updateFilters(array $filters): void
{
$this->filters = $filters;
$this->resetPage();
}
public function render()
{
return view('livewire.product-results', [
// Re-validated here too — a hand-crafted Livewire payload can't smuggle a column in.
'products' => FilteredQuery::for(Product::class)->withFilters($this->filters)->paginate(15),
]);
}
}
resources/views/livewire-page.blade.php
this page @extends('layout')
@section('title', 'Livewire — Advanced Filters')
@section('heading', 'Livewire')
@section('frontend', 'no page reload — the panel dispatches, the table re-queries')
@push('head')
@livewireStyles
{{-- No CDN Alpine here: Livewire ships its own, and loading a second breaks both. --}}
<script type="module">
import '{{ asset('vendor/advanced-filters/advanced-filters.js') }}?v={{ filemtime(public_path('vendor/advanced-filters/advanced-filters.js')) }}'
</script>
@endpush
@section('content')
<div class="card">
<livewire:advanced-filters::panel :model="\App\Models\Product::class" />
</div>
<livewire:product-results />
@include('_code', [
'intro' => 'Same model as the Blade page — <strong>not a line of filter logic changes</strong>.
The panel dispatches an event; the results component listens and re-queries.',
'files' => [
['path' => 'app/Models/Product.php', 'note' => 'identical on all three pages'],
['path' => 'app/Livewire/ProductResults.php', 'note' => 'listens for the event'],
['path' => 'resources/views/livewire-page.blade.php', 'note' => 'this page'],
],
])
@endsection
@push('scripts')
@livewireScripts
@endpush