A
A
axblue2017-02-02 15:22:49
Laravel
axblue, 2017-02-02 15:22:49

How to properly write nested routes?

Hello. You need to make routes:

sitename.ru/articles //получаем все артиклы
sitename.ru/articles/slugArticle //переход на артикл из ./articles
sitename.ru/articles/slugCategory  //выводим артиклы данной категории
sitename.ru/articles/slugCategory/slugArticle  //переход по артиклу данной категории

I can’t understand how to register it in routes, I do something like:
Route::get('/recipes','[email protected]');
Route::get('/recipes/{slugRecipe}','[email protected]');
Route::get('/recipes/{slugTag}', '[email protected]');
Route::get('/recipes/{slugTag}/{slugRecipe}', '[email protected]');

Naturally, Lara swears at me for such crooked routes ... Poke your finger on how to implement it correctly.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrzej Wielski, 2017-02-02
@leshikgo

You cannot create the same routes for different controllers.
I can advise you to create a single controller, for example RouteController , in which to search for Article by the passed slug. If it is found, call the required method from the ArticlesController, if not, call it from the CategoriesController.

A
Alexander Aksentiev, 2017-02-02
@Sanasol

Naturally, Lara scolds me for such crooked routes...

Of course, I will not show an error (and google it).
Everything is fine with the routes, at least at first glance.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question