V
V
vista1x2019-06-05 17:01:28
Laravel
vista1x, 2019-06-05 17:01:28

How to make a dynamic prefix for a router?

There is a project in which it is necessary to display the name of the city as a prefix for some pages , that
is
: , all addresses must go to their controllers, regardless of the prefix. What is the best way to implement this? How to use a dynamic prefix (including the option without a prefix should work)? I tried many different options, everything works somehow crookedly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rustam Sadykov, 2019-06-09
@TrueKanonir

Let's say the visitor has chosen a region, and we have put the code of this region in his session.
Then you can do this:

Route::prefix(session('region_code'))->group(function() {
    Route::get('catalog', '...');
    // ...
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question