PHP code example of dividing-zero / laravel-dynamic-sitemap
1. Go to this page and download the library: Download dividing-zero/laravel-dynamic-sitemap library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dividing-zero / laravel-dynamic-sitemap example snippets
return [
/*
|--------------------------------------------------------------------------
| Models
|--------------------------------------------------------------------------
|
| List fully qualified model class names to Modified Date
|--------------------------------------------------------------------------
|
| The default modified date to use when a model does not define a `getModifiedDate` method.
| This will also be used for any routes which are manually iddleware, so a reasonable default such as 'monthly' is recommended.
| Options: always, hourly, daily, weekly, monthly, yearly, never
|
*/
'default_change_frequency' => 'monthly',
/*
|--------------------------------------------------------------------------
| Default Priority
|--------------------------------------------------------------------------
|
| The default priority to use when a model does not define a `getPriority` method.
| This will also be used for any routes which are manually
use DividingZero\LaravelDynamicSitemap\Traits\Sitemappable;
class Post extends Model
{
use Sitemappable;
// Required overrides
/**
* Define the sitemap URL for this model instance.
*
* @return string
*/
public function getSitemapUrl(): string;
// Optional overrides
/**
* Get the last modification date for the sitemap entry.
*
* @return \Carbon\Carbon
*/
public function getSitemapModifiedDate(): Carbon
{
return $this->updated_at ?? Carbon::parse(config('sitemap.default_modified_date'));
}
/**
* Get the change frequency for the sitemap entry.
*
* @return string (e.g., 'daily', 'weekly')
*/
public function getSitemapChangeFreqency(): string
{
// Use config default if not overridden
return config('sitemap.default_change_frequency');
}
/**
* Get the priority for the sitemap entry.
*
* @return float
*/
public function getSitemapPriority(): float
{
// Use config default if not overridden
return config('sitemap.default_priority');
}
/**
* Scope a query to only