In this episode, we're building out the individual product page over on the user's marketplace, which is displayed under their subdomain. We start by improving the navigation so users can easily jump to their marketplace, even on smaller screens, and make sure the links direct to the right subdomain-based routes using the current user.
Next, we set up a new controller and route for displaying a specific product using its slug (instead of the ID, for cleaner and more user-friendly URLs). We then create the associated Blade view, keeping it simple, showing the product name, a link back to the seller's store, the product description, and a prominent, styled Buy Now button that shows the properly formatted price.
We also make use of a money library, which lets us neatly output the price as a formatted string without any extra effort. Then, to keep things secure, we introduce authorization: by setting up a Product Policy and registering it, we ensure that only products which are "live" can be viewed. We use Laravel's policy system so that requests to view non-live products are automatically denied.
Finally, we tweak the policy so that guest users (or anyone on the subdomain who isn't authenticated) are handled properly, making access seamless for visitors, while still keeping unpublished products protected. By the end, we have a tidy, secure product page that only shows available products and has all the navigation you'd expect!