Add Advanced Search and filtering to Posts
- Add full-text search index on posts.title and posts.body - Add search box with live filtering - Add filter dropdowns for type, status, and site - Add Clear Filters button - Display post count in filter bar - All filters work together (AND logic) Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -40,9 +40,39 @@ class Index extends Component
|
||||
|
||||
public ?string $publishNotice = null;
|
||||
|
||||
public string $search = '';
|
||||
|
||||
public string $typeFilter = '';
|
||||
|
||||
public string $statusFilter = '';
|
||||
|
||||
public string $siteFilter = '';
|
||||
|
||||
public function render()
|
||||
{
|
||||
$posts = Post::with(['site', 'socialAccounts'])->orderByDesc('created_at')->get();
|
||||
$query = Post::with(['site', 'socialAccounts']);
|
||||
|
||||
// Full-text search on title and body
|
||||
if ($this->search) {
|
||||
$query->whereFullText(['title', 'body'], $this->search);
|
||||
}
|
||||
|
||||
// Filter by type
|
||||
if ($this->typeFilter) {
|
||||
$query->where('type', $this->typeFilter);
|
||||
}
|
||||
|
||||
// Filter by status
|
||||
if ($this->statusFilter) {
|
||||
$query->where('status', $this->statusFilter);
|
||||
}
|
||||
|
||||
// Filter by site
|
||||
if ($this->siteFilter) {
|
||||
$query->where('site_id', $this->siteFilter);
|
||||
}
|
||||
|
||||
$posts = $query->orderByDesc('created_at')->get();
|
||||
|
||||
return view('livewire.posts.index', [
|
||||
'posts' => $posts,
|
||||
@@ -78,6 +108,14 @@ class Index extends Component
|
||||
$this->showForm = true;
|
||||
}
|
||||
|
||||
public function clearFilters(): void
|
||||
{
|
||||
$this->search = '';
|
||||
$this->typeFilter = '';
|
||||
$this->statusFilter = '';
|
||||
$this->siteFilter = '';
|
||||
}
|
||||
|
||||
public function createFromTemplate(int $templateId): void
|
||||
{
|
||||
$template = Template::findOrFail($templateId);
|
||||
|
||||
Reference in New Issue
Block a user