I want to provide my customer with an option to configure their subdomain names in .env and config/app.php file. My Laravel route configuration is as follows:
Route::group(['namespace' => 'PublicSite',
'domain' => config('app.app_domain_public')], function () {
// public routes here
});
Route::group(['namespace' => 'AdminSite',
'domain' => config('app.app_domain_admin')], function () {
// admin routes here
});
It works fine and reacts to .env changes. But when I prepare my application package for deployment, I run php artisan route:cache
and this makes the values of config('app.app_domain_x')
frozen somewhere in bootstrap/cache/routes.php
.
As the result, the application no more reacts to route domain changes in .env
unless I run php artisan route:cache
on the server. But there are situations when it's not possible to run artisan on the server.
Of course, I could configure .env
as necessary before deployment but this breaks the idea of being able to modify .env
settings without rewriting other application files (route cache, to be more specific).
Is there any workaround to make Laravel to cache at least some routes but still provide dynamic domain configuration?