You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into this when I a collegue wanted to change the default behaviour of a model's returned url (create a different priority).
In your example, you show how to add the functionality to the model, only returning a string of its route.
This is the current example:
use Spatie\Sitemap\Contracts\Sitemapable;
use Spatie\Sitemap\Tags\Url;
class Post extends Model implements Sitemapable
{
public function toSitemapTag(): Url | string | array
{
return route('blog.post.show', $this);
}
}
It does clearly show the returnable types, but perhaps an example like:
use Spatie\Sitemap\Contracts\Sitemapable;
use Spatie\Sitemap\Tags\Url;
class Post extends Model implements Sitemapable
{
public function toSitemapTag(): Url | string | array
{
return Url::create(route('blog.post.show', $this))
->setLastModificationDate(Carbon::yesterday())
->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY)
->setPriority(0.1);
}
}
might show people quickly that they can infact easily change this per model, even adding in some model specific logic if need be.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
First of all, thank you for this awesome package.
I ran into this when I a collegue wanted to change the default behaviour of a model's returned url (create a different priority).
In your example, you show how to add the functionality to the model, only returning a string of its route.
This is the current example:
use Spatie\Sitemap\Contracts\Sitemapable;
use Spatie\Sitemap\Tags\Url;
class Post extends Model implements Sitemapable
{
public function toSitemapTag(): Url | string | array
{
return route('blog.post.show', $this);
}
}
It does clearly show the returnable types, but perhaps an example like:
use Spatie\Sitemap\Contracts\Sitemapable;
use Spatie\Sitemap\Tags\Url;
class Post extends Model implements Sitemapable
{
public function toSitemapTag(): Url | string | array
{
return Url::create(route('blog.post.show', $this))
->setLastModificationDate(Carbon::yesterday())
->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY)
->setPriority(0.1);
}
}
might show people quickly that they can infact easily change this per model, even adding in some model specific logic if need be.
Just a thought.
Kind regards
Elwin Bergsma
Beta Was this translation helpful? Give feedback.
All reactions