1
0
Fork 0
mirror of https://github.com/archtechx/laravel-seo.git synced 2025-12-12 09:54:03 +00:00
This commit is contained in:
Ben Bjurstrom 2025-03-06 18:55:14 -05:00 committed by GitHub
commit f4b40ca38d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 2 deletions

View file

@ -224,9 +224,13 @@ class SEOManager
} }
/** Append canonical URL tags to the document head. */ /** 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; return $this;
} }

View file

@ -118,6 +118,16 @@ test('canonical url can be read from request', function () {
->toContain('<link rel="canonical" href="http://localhost">'); ->toContain('<link rel="canonical" href="http://localhost">');
}); });
test('canonical url accepts origin', function () {
$this->get('/testing/5');
seo()->withUrl('https://foo.com');
expect(meta())
->toContain('<meta property="og:url" content="https://foo.com/testing/5">')
->toContain('<link rel="canonical" href="https://foo.com/testing/5">');
});
test('canonical url can be changed', function () { test('canonical url can be changed', function () {
seo()->withUrl(); seo()->withUrl();