In this episode, we take our discussion filters to the next level by adding two new ones that are only available to authenticated users: "My Discussions" and "Participating". We start by updating the UI so that these extra filter options only show up when you're logged in. There’s a quick debugging moment where clicking "login" accidentally tries to load a discussion with a slug of "login"—but we fix that by updating the route prefix.
With the UI refreshed, we dive into creating the actual filters on the backend. First, we add the "my discussions" query filter, which makes sure to only return the discussions you've personally started. We also put in a safety check so nothing weird happens if a user isn't authenticated when using the filter.
Next, we tackle the "participating" filter, which finds discussions where you've posted replies (but crucially, not ones you've created yourself). This is a bit trickier, so we use a combination of whereHas
and a smart check to make sure the discussion owner isn't you. After we register these new filters, everything is looking good — selecting each filter shows exactly what you'd expect.
Basically, by the end of this episode, your forum now offers personalized ways for users to view discussions, making things a lot more user-friendly for people who are signed in.