diff --git a/src/SEOManager.php b/src/SEOManager.php index a24d0c2..58a4c85 100644 --- a/src/SEOManager.php +++ b/src/SEOManager.php @@ -224,9 +224,13 @@ public function favicon(): static } /** Append canonical URL tags to the document head. */ - public function withUrl(): static + public function withUrl(?string $origin = null): static { - $this->url(request()->url()); + if ($origin) { + $this->url(trim($origin, '/') . '/' . trim(request()->path(), '/')); + } else { + $this->url(request()->url()); + } return $this; } diff --git a/tests/Pest/ManagerTest.php b/tests/Pest/ManagerTest.php index a78b165..b041438 100644 --- a/tests/Pest/ManagerTest.php +++ b/tests/Pest/ManagerTest.php @@ -118,6 +118,16 @@ ->toContain(''); }); +test('canonical url accepts origin', function () { + $this->get('/testing/5'); + + seo()->withUrl('https://foo.com'); + + expect(meta()) + ->toContain('') + ->toContain(''); +}); + test('canonical url can be changed', function () { seo()->withUrl();