A
A
Alexey Sklyarov2021-08-12 11:38:57
Laravel
Alexey Sklyarov, 2021-08-12 11:38:57

How to solve the problem with the naming of routes in the presence of subdomains?

There is a project for which regional pages should be implemented, then each city has its own subdomain {city}.site.ru. I added to RouteServiceProvider.php the connection of the file with routes twice, for the main domain and subdomains:

Route::domain(env('APP_DOMAIN_URL'))
                ->middleware('web')
                ->namespace($this->namespace)
                ->group(base_path('routes/web.php'));

            Route::domain('{city}.' . env('APP_DOMAIN_URL'))
                ->middleware('web')
                ->namespace($this->namespace)
                ->group(base_path('routes/web.php'));


The routes themselves look like this:
Route::view('/policy', 'web.sections.static.policy')->name('policy');


But with this connection, due to the fact that I use names for routes, I get an error about duplicating names (since the same routes are used for the main domain and city subdomains). How can this problem be corrected?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tolmachev, 2021-08-12
@0example

Don't double enter routes. This is fundamentally wrong. Possible options in your case:
1. Analyze the domain at the middleware level, and skip subdomains, if there are any in the request. And then steer the logic. Remove the division into subdomains and the base one from the routes.
2. Find out what Tenant is https://tenancyforlaravel.com/
3. Make prefixes in routes (which is not comme il faut in your case)
3 Think again about the logic of the pages, perhaps you don’t need named routes there.
Well, if you are friends with English: "Dynamic custom domain routing in Laravel" Google to help

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question