I need to create a site (e-shop) in Laravel using SEO-friendly and hierarchical URLs.
Some examples are:
www.example.com/cat1/cat11
(which points to a category product-listing)www.example.com/cat1/cat11/cat111
(which points to a category product-listing)www.example.com/cat1/cat11/cat111/product-title
(which points to a product-details page)www.example.com/contact-us
(which points to a page)
I can parse the above URLs and find the needed slug, but I am not sure which controller will be responsible for each route.
Possible thoughts:
1) Add prefix to each URL type, in order to know the controller e.g.
www.example.com/categories/cat1/cat11/cat111
> CategoryControllerwww.example.com/products/cat1/cat11/cat111/product-title
> ProductControllerwww.example.com/page/contact-us
> PageController
2) Pre-generate and store in a table all the site's URLs. The table can contain two columns: the URL (cat1/cat11/cat111) and the model:id (category:8) A global controller will parse the URL and using the table can load the required model & id.
Any other idea?