PHP code example of gavtaylor / laravel-sitemap

1. Go to this page and download the library: Download gavtaylor/laravel-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/ */

    

gavtaylor / laravel-sitemap example snippets


// config/sitemap.php
'label_glossary' => [
    'eca' => 'ECA',
    'reach newsletter' => 'REACH Newsletter',
],

// config/sitemap.php
'sync_robots_after_commands' => ['migrate'], // the default; [] to disable

   Route::name('about-us.')->group(function () {
       Route::get('/about-us', ...)->name('index');       // about-us.index
       Route::get('/six-point-plan', ...)->name('plan');  // about-us.plan
   });
   

// config/sitemap.php
'excluded_middleware' => ['auth', 'auth:*', 'signed', 'password.confirm'], // the default
'excluded_route_names' => ['admin.*'],
'excluded_paths' => ['internal/*'],

// config/sitemap.php
'route_resolvers' => [
    'blog.show' => \App\Sitemap\PostSlugs::class,
],

final class PostSlugs
{
    public function __invoke(): array
    {
        return array_keys(

final class PostSlugs
{
    public function __invoke(): array
    {
        return collect(ug' => $slug],
                'label' => $post['title'],
                'lastmod' => $post['updated_at'] ?? null,
            ])
            ->values()
            ->all();
    }
}

'cache_seconds' => 3600, // 0 disables caching entirely

'clear_cache_after_commands' => ['migrate'], // the default; [] to disable

'lastmod_resolver' => null, // an invokable class-string, e.g. \App\Sitemap\LastmodResolver::class
bash
php artisan vendor:publish --tag=sitemap-views
bash
php artisan vendor:publish --tag=sitemap-config
bash
php artisan sitemap:clear