diff --git a/app/Livewire/Posts/Index.php b/app/Livewire/Posts/Index.php index a4b6657..dd10106 100644 --- a/app/Livewire/Posts/Index.php +++ b/app/Livewire/Posts/Index.php @@ -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); diff --git a/database/migrations/2026_07_27_000004_add_fulltext_search_to_posts.php b/database/migrations/2026_07_27_000004_add_fulltext_search_to_posts.php new file mode 100644 index 0000000..1cac53a --- /dev/null +++ b/database/migrations/2026_07_27_000004_add_fulltext_search_to_posts.php @@ -0,0 +1,22 @@ +fullText(['title', 'body']); + }); + } + + public function down(): void + { + Schema::table('posts', function (Blueprint $table) { + $table->dropFullText(['title', 'body']); + }); + } +}; diff --git a/resources/views/livewire/posts/index.blade.php b/resources/views/livewire/posts/index.blade.php index dbcc316..fe75676 100644 --- a/resources/views/livewire/posts/index.blade.php +++ b/resources/views/livewire/posts/index.blade.php @@ -8,6 +8,59 @@
{{ $publishNotice }}
@endif + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ Showing {{ $posts->count() }} post{{ $posts->count() !== 1 ? 's' : '' }} +
+
+