S
S
Ssonik2020-10-26 18:45:37
Laravel
Ssonik, 2020-10-26 18:45:37

How to handle different data at the same url nesting level?

How to be in such cases?

Route::get('/{page}', 'Frontend\[email protected]');
Route::get('/{catalog}', 'Frontend\[email protected]');
Route::get('/{catalog}/{filters?}', 'Frontend\[email protected]');
Route::get('/{catalog}{product}', 'Frontend\[email protected]');

The first solution that comes to mind is to create 1 route for page and catalog, then search the database by url and give different results.

What if there are 10,000 pages? What if there are 3 different types of pages and you need to keep the url at level 1? Etc.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
JhaoDa, 2020-10-26
@Ssonik

Use prefixes:

Route::get('/page-{page}', 'Frontend\[email protected]');
Route::get('/catalog-{catalog}', 'Frontend\[email protected]');
Route::get('/catalog-{catalog}/{filters?}', 'Frontend\[email protected]');
Route::get('/catalog-{catalog}/product-{product}', 'Frontend\[email protected]');

P
pLavrenov, 2020-10-27
@pLavrenov

Since the above is only .... everywhere they say that you need to use multiple resource naming but I don’t like it ...

Route::get('/page/{page}', 'Frontend\[email protected]');
Route::get('/catalog/{catalog}', 'Frontend\[email protected]');
Route::get('/catalog/{catalog}/{filters?}', 'Frontend\[email protected]');
Route::get('/catalog/{catalog}/product/{product}', 'Frontend\[email protected]');

Naming complex actions in REST API

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question