posted 5 years ago
Slugs should only be an after-thought. Don't use them to identify a resource. First design your URLs so they unambiguously locate a resource:
https://example.com/shop/categories/laptops
https://example.com/shop/products/macbook-pro-ssd
If you still need the slug, for instance when you're using integers for ids rather than unique names, you add them to the URL *after* the URL contains enough information to identify the resource:
https://example.com/shop/categories/5/laptops
https://example.com/shop/products/24/macbook-pro-ssd
In the above code, the index() action will map the {id} part of the URL to the id method parameter, and ignore everything that comes afterwards.