Mity Docs Mity Docs for Mity Digital
Sitemapamic Documentation

SitemapamicUrl object

The SitemapamicUrl object is used when you are adding Dynamic Routes to your sitemaps.

Properties

Argument

Type

Required

Description

loc

string

Yes

The page's full URL. It must be an absolute http or https URL.

lastmod

?string

No

The page's last modified date, written to <lastmod> exactly as given. Use a W3C datetime, such as $date->toW3cString(). Left out when null.

changefreq

ChangeFrequency|string|null

No

One of always, hourly, daily, weekly, monthly, yearly or never, as a string or a ChangeFrequency enum case. Left out when null.

priority

?float

No

A value from 0.0 to 1.0. Left out when null.

alternates

array

No

Alternate language versions of the page, as ['hreflang' => '…', 'href' => '…'] pairs. Each href must be an absolute URL.

Use

1use MityDigital\Sitemapamic\Enums\ChangeFrequency;
2use MityDigital\Sitemapamic\Models\SitemapamicUrl;
3 
4new SitemapamicUrl(
5 loc: 'https://example.com/events',
6 lastmod: $latestEvent->updated_at->toW3cString(),
7 changefreq: ChangeFrequency::Daily,
8 priority: 0.8,
9 alternates: [
10 ['hreflang' => 'en', 'href' => 'https://example.com/events'],
11 ['hreflang' => 'fr', 'href' => 'https://example.com/fr/evenements'],
12 ],
13);

Validation

  • A loc or alternate href that isn't an absolute http/https URL throws an InvalidArgumentException when the sitemap is built.

  • The closure must return an iterable containing only SitemapamicUrl objects. Anything else throws an InvalidArgumentException.

  • A changefreq that isn't one of the allowed values, or a priority outside 0–1, is left out of that URL without an error.