M
M
MasterCopipaster2020-11-05 19:57:10
Laravel
MasterCopipaster, 2020-11-05 19:57:10

How to pass url part in laravel controller?

Guys tell me how to do it: I have a url like /api/v1/products/category/sub-data-1/sub-data-2/sub-data-n
I need to use the controller at /api/v1/products/ and then pass the rest of the url category/sub-data-1/sub-data-2/sub-data-n to the controller for processing.
I actually tried to do it like this

Route::get('products/{slug}', '[email protected]')->where(['slug' => '^(.*?)$/']);

But it gives 404, tell me how to tell the routing that everything after products is the ProductController controller?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dinesh_Chugtai, 2020-11-05
@MasterCopipaster

Try the following option, in my case everything after products/* is captured

Route::get('products/{any}', '[email protected]')->where('any', '.*');

Apparently you want to implement the nesting of categories, it's not easier to make the following url:
/api/v1/products/category?id=1 // Получаем определенную категорию
 /api/v1/products?category_id=1 // Получаем товар с определенной категорией

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question