1 year ago

Categories, Products and Routing

Posted 1 year ago by elliotk

Ok guys, here's the thing....

I've created a model for Categories which works nicely with Sub Categories (from an Eloquent perspective)

Cat 1
Cat 1 -> Sub 1
Cat 1 -> Sub 1 -> Sub 2
Cat 1 -> Sub 1 -> Sub 2 -> Sub 3

I really don't want to limit the depth unless I have to.

I then have a Product Model, and any given Product can be associated to any level of category, I had in mind that a Product would be placed in the lowest category, and roll up, but I may have it so that it needs to be placed at every level - we'll see.

URL's will look like this (all driven on slugs)


So a few questions

  1. How do you handle N depth of category in the route?
  2. How then do you determine whether a given route is a Product or a Category?

I'm considering some kind of centralised slug management, which allows unique slugs and determines the correct controller to hand off to. Seems complex.

Part of me things I should just do

/sub2 (which is really /cat1/sub2)


I just feel, for nested categories, you lose some readability if the categories don't stack in the address bar and tell a story?

I welcome all and any feedback.

Please sign in or create an account to participate in this conversation.