T
T
turindd2021-07-12 11:33:21
Laravel
turindd, 2021-07-12 11:33:21

How to build a URL from multiple subcategories?

Dear programmers!
Please explain how to competently build a URL from many subcategories?

I have a page - all categories (general menu).

// роут
 Route::get('/category', '[email protected]')->name('category.index');
// контроллер
public function index()


from this page, I have to go to .ru/category/odegda/zhenskaya
for this I have:
// роут
Route::get('/category/{alias?}', '[email protected]')->name('category.one');
// контроллер
public function one($alias, Request $request)
// через ссылку
<a title="{{ $v['name'] }}" href="{{ route('category.one', $v['url']) }}">

but I can't pass the parameter (odegda/zhenskaya).
404 not found
possibly because $v['url'] is not a laravel object.
what should I do then?

Thanks in advance for any answer!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
turindd, 2021-07-12
@turindd

Route::get('/category/{alias?}', '[email protected]')->where('alias', '(.*)')->name('category.one');

D
Dmitry Baskakov, 2021-07-12
@dmitrybascacov

There is an option, use the where method and write a regular expression there, if you understand the problem correctly
https://laravel.com/docs/8.x/routing#parameters-re...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question