I’m implementing category structure , some products would have one level category but other may have two or more level :
/posts/cat2/post-sulg
/posts/cat-1/sub-1/post-slug
/posts/cat-3/sub../../../post-slug
as i dont know how depth it would be and using category slugs is only for seo (i find post only by its slug) what is the best way to create a route to handle this structure?
3
Answers
You can solve this with:
And then in controller
I did something similar, this in PostController.php using
In routes/web.php
If you want to use the full category list as the slug, just change the slug function:
I spend many hours for researching, googing, testing to achive this and this is the most simpy way and clean way!
You will achive this:
Before start:
Example:
You write post about BMW tyres:
So in DB slug column you save value like this:
Steps how i slove this
First make route
Here take care to provide ? on param. If you miss this you can’t route homepage. Category will be required!
Second
Create controller method
Category Blade
Post Blade
Whit this you cant make mistake. Dont waste hours like me! I just provide simple example you can now have new idea!