PHP code example of ismailnakkar / laravel-seo

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

    

ismailnakkar / laravel-seo example snippets


$seo->sitemapUsing(function (): iterable {
    foreach (Post::query()->select(['slug', 'updated_at'])->lazy() as $post) {
        yield new SitemapEntry("/blog/{$post->slug}", $post->updated_at);
    }
});

$seo->siteUsing(fn (Settings $settings): array => ['name' => $settings->siteName()]);

$seo->alternatesUsing(function (\Illuminate\Routing\Route $route, string $path): ?array {
    if (! in_array('locale', $route->parameterNames(), true)) {
        return null; // not localized
    }

    $rest = preg_replace('~^/[^/]+~', '', $path);          // /fr/terms → /terms
    $code = rawurldecode(explode('/', $path)[1]);         // /%66r/terms → fr

    return [
        'path' => "/{$code}{$rest}",
        'alternates' => collect(['en', 'fr', 'es'])->mapWithKeys(fn ($c) => [$c => "/{$c}{$rest}"])->all(),
    ];
});

$this->assertSitemapComplete();
$this->assertTrue($this->robotsTxt('example.com')->allows('Googlebot', '/pricing'));