A
A
Anton_a462020-07-24 17:42:27
Laravel
Anton_a46, 2020-07-24 17:42:27

How to get an array of route parameters?

There is a route like this: {prefix}/{parent_slug}/{id}
You can either pass an array of the form to the controller somehow:

[
'prefix' => текущее значение данного элемента маршрута
'parent_slug' => текущее значение данного элемента маршрута
'id' => текущее значение данного элемента маршрута
]


The fact is that there are several types of addresses that the controller must process and redirect to a single address.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2020-07-24
@Anton_a46

since they are already available in the controller, why pass them?

public function method( Request $request ) {
     $request->prefix;
     $request->parent_slug;
     $request->id;
}

A
Anton_a46, 2020-07-24
@Anton_a46

As it turned out, I can get the array I need in the controller:
{"parent_slug":"kategoriya-4","id":"5"}
Using $request->route()->originalParameters();
Found in documentation:
https://laravel.com/api/5.8/Illuminate/Routing/Rout...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question