diff --git a/src/Assets/AssetContainer.php b/src/Assets/AssetContainer.php index 29765fce49..d9ef83d6a1 100644 --- a/src/Assets/AssetContainer.php +++ b/src/Assets/AssetContainer.php @@ -27,6 +27,7 @@ use Statamic\Facades\Stache; use Statamic\Facades\URL; use Statamic\Support\Arr; +use Statamic\Support\Str; use Statamic\Support\Traits\FluentlyGetsAndSets; class AssetContainer implements Arrayable, ArrayAccess, AssetContainerContract, Augmentable @@ -138,7 +139,8 @@ public function url() return null; } - $url = rtrim($this->disk()->url('/'), '/'); + $url = Str::removeRight($this->disk()->url('/'), '/'); + $url = Str::removeLeft($url, config('app.url')); return ($url === '') ? '/' : $url; } diff --git a/tests/Assets/AssetContainerTest.php b/tests/Assets/AssetContainerTest.php index 507c735879..9bc8f92ffe 100644 --- a/tests/Assets/AssetContainerTest.php +++ b/tests/Assets/AssetContainerTest.php @@ -137,6 +137,21 @@ public function it_gets_the_url_from_the_disk_config_when_its_relative() $this->assertEquals('http://localhost/container', $container->absoluteUrl()); } + #[Test] + public function it_gets_the_url_from_the_disk_config_when_its_app_url() + { + config(['filesystems.disks.test' => [ + 'driver' => 'local', + 'root' => __DIR__.'/__fixtures__/container', + 'url' => 'http://localhost/container', + ]]); + + $container = (new AssetContainer)->disk('test'); + + $this->assertEquals('/container', $container->url()); + $this->assertEquals('http://localhost/container', $container->absoluteUrl()); + } + #[Test] public function its_private_if_the_disk_has_no_url() {