V
V
VladimirKrasnov2021-01-14 17:40:46
Laravel
VladimirKrasnov, 2021-01-14 17:40:46

How to make route for Laravel categories?

There are several categories and subcategories on the site, how to implement routes correctly so that you can jump by category?

There is such an option

Route::get('{category1}/{category2?}/{category3?}/{category4?}',
    '[email protected]');

But the problem is that the admin himself can add parent categories and children. Here, the route works with 4 kids, but what if the admin makes 44 subcategories? How to be in this case, each time rewrite the route and constantly {add this?}.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2021-01-14
@VladimirKrasnov

Laravel how to implement hierarchical route?

D
Dmitry, 2021-01-14
@DKWLB

It is more logical to make one common parameter for subcategories /{subcategories} and then in the controller split the string and get an array of subcategories.
P.s. There was a similar question a couple of hours ago.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question