Answer the question
In order to leave comments, you need to log in
How to do routing in Laravel?
Hello. When creating the site, there were originally routes for categories and subcategories:
Route::pattern('category', '[a-zA-Z0-9\-]+'); // Такие паттерны у всех роутов
Route::get('/{auto}/{country}/', ['as' => 'country', 'uses' => '[email protected]']);
Route::get('/{auto}/{country}/archive/', ['as' => 'country.archive', 'uses' => '[email protected]']);
Route::get('/{auto}/{country}/{mark}/', ['as' => 'mark', 'uses' => '[email protected]']);
Route::get('/{auto}/{country}/{mark}/archive/', ['as' => 'mark.archive', 'uses' => '[email protected]']);
Route::get('/{category}/', ['as' => 'category.list', 'uses' => '[email protected]']);
Route::get('/{category}/{article_slug}/', ['as' => 'article', 'uses' => '[email protected]']);
<?php echo link_to_route('category.list', 'obuchenie', ['obuchenie'] ); ?>
<?php echo link_to_action('[email protected]', 'obuchenie2', ['obuchenie'] ) ?>
<a href="{{route('category.list',['obuchenie']) }}">obuchenie3</a>
Route::get('/{page}/', ['as' => 'page', 'uses' => [email protected]']);
Answer the question
In order to leave comments, you need to log in
How does he know {auto} is different from {page} or {category}? The answer is no, since they are identical, so auto always works.
You need to come up with either a Route::prefix('auto') prefix (of type auto_{auto}), or write a naming rule for each pattern (to variables that form the path, ), or write a handler inside that, if it does not find auto, according to the rules, it will be thrown on page, etc.).
In short, study https://laravel.com/docs/5.4/routing , it is possible to paint your own router logic, but this will complicate everything.
I think your option is to switch to prefixes and everything will work beautifully and quickly.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question