diff --git a/src/Foundation/Bootstrap/RegisterOctober.php b/src/Foundation/Bootstrap/RegisterOctober.php index 786c530f0..633d264f6 100644 --- a/src/Foundation/Bootstrap/RegisterOctober.php +++ b/src/Foundation/Bootstrap/RegisterOctober.php @@ -41,11 +41,6 @@ class RegisterOctober */ public function bootstrap(Application $app) { - // Workaround for CLI and URL based in subdirectory - if ($app->runningInConsole()) { - $app['url']->forceRootUrl($app['config']->get('app.url')); - } - // Register singletons $app->singleton('string', function () { return new \October\Rain\Support\Str; diff --git a/src/Html/UrlServiceProvider.php b/src/Html/UrlServiceProvider.php index 28a464364..969032a1c 100644 --- a/src/Html/UrlServiceProvider.php +++ b/src/Html/UrlServiceProvider.php @@ -1,7 +1,5 @@ registerUrlGeneratorPolicy(); $this->registerRelativeHelper(); $this->registerPjaxCached(); + + $this->app['events']->listen('site.changed', function() { + $this->registerUrlGeneratorPolicy(); + }); } /** @@ -33,14 +35,13 @@ public function register() public function registerUrlGeneratorPolicy() { $provider = $this->app['url']; - $policy = Config::get('system.link_policy', 'detect'); + $policy = $this->app['config']->get('system.link_policy', 'detect'); + $appUrl = $this->app['config']->get('app.url'); switch (strtolower($policy)) { case 'force': - $appUrl = Config::get('app.url'); - $schema = Str::startsWith($appUrl, 'http://') ? 'http' : 'https'; $provider->forceRootUrl($appUrl); - $provider->forceScheme($schema); + $provider->forceScheme(str_starts_with($appUrl, 'http://') ? 'http' : 'https'); break; case 'insecure': @@ -51,6 +52,13 @@ public function registerUrlGeneratorPolicy() $provider->forceScheme('https'); break; } + + // Workaround for October CMS installed to a subdirectory since + // Laravel won't support this use case, related issue: + // https://github.com/laravel/framework/pull/3918 + if ($this->app->runningInConsole()) { + $provider->forceRootUrl($appUrl); + } } /**