Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

refactor(posts): use $request->collect() + when() for label filter

Paulo Castellano66f4d8c7b3f8
diff --git a/app/Http/Controllers/App/PostController.php b/app/Http/Controllers/App/PostController.php
index 1d6ef675e..8c4331231 100644
--- a/app/Http/Controllers/App/PostController.php
+++ b/app/Http/Controllers/App/PostController.php
@@ -57,13 +57,15 @@ class PostController extends Controller
$query->where('content', 'ilike', "%{$search}%");
}
- $labelIds = array_values(array_filter(
- (array) $request->input('labels', []),
- fn ($id) => is_string($id) && $id !== '',
+ $labelIds = $request->collect('labels')
+ ->filter(fn ($id) => is_string($id) && $id !== '')
+ ->values()
+ ->all();
+
+ $query->when($labelIds, fn ($q) => $q->whereHas(
+ 'labels',
+ fn ($q) => $q->whereIn('workspace_labels.id', $labelIds),
));
- if (! empty($labelIds)) {
- $query->whereHas('labels', fn ($q) => $q->whereIn('workspace_labels.id', $labelIds));
- }
return Inertia::render('posts/Index', [
'workspace' => $workspace,