In this episode, we're focusing on making sure that products that aren't marked as "live" in our database don't show up anywhere on our site. That means hiding them from the search results, category listings, and making it so you can't even access them directly with a URL.
The main approach here is using a global scope in our Product model. We walk through adding a booted
static method to the model, then setting up a dedicated LiveScope class in a scopes
directory. This scope checks the live_at
field and only includes products where it's not null (which means they're live).
Once that's in place, we test it out: set a product to not be live, and we see it disappears from everywhere—even from Meilisearch search queries after we flush and re-import with Scout. The result is a much cleaner and more secure product experience. Don’t worry, you can always tweak the scope later if you need an exception.
So, by the end of this, we've locked down access to non-live products everywhere in the application, making our product listings and search much more robust.