PHP code example of asignua / filament-seo-files

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

    

asignua / filament-seo-files example snippets


use Asignua\FilamentSeoFiles\SeoFilesPlugin;

$panel->plugin(SeoFilesPlugin::make()
    ->authorize(fn (): bool => auth()->user()?->isAdmin()));

use Asignua\FilamentSeoFiles\SeoFiles;
use Asignua\FilamentSeoFiles\Sources\ModelSource;

SeoFiles::source(
    ModelSource::make(Post::class)
        ->query(fn ($query) => $query->where('published', true))
        ->url(fn (Post $post, string $locale): ?string => route('posts.show', $post))
        ->title(fn (Post $post, string $locale): string => $post->title)
        ->description(fn (Post $post, string $locale): ?string => $post->excerpt)
        ->body(fn (Post $post, string $locale): string => $post->content) // HTML or Markdown
        ->section('Blog'),
);

SeoFiles::locales(default: 'en', all: ['en', 'uk', 'de'], unprefixed: 'en');

SeoFiles::baseUrlUsing(fn (): string => config('app.url'));            // default: app.url
SeoFiles::localizedUrlUsing(fn (string $locale, string $path): string => …); // default: {base}/[{locale}/]{path}
SeoFiles::siteNameUsing(fn (string $locale): string => …);             // default: app.name
SeoFiles::descriptionUsing(fn (string $locale): ?string => …);         // default: none

use Asignua\FilamentSeoFiles\Contracts\LlmsFullSource;
use Asignua\FilamentSeoFiles\Contracts\LlmsIndexSource;
use Asignua\FilamentSeoFiles\Contracts\SitemapSource;
use Asignua\FilamentSeoFiles\Data\LlmsDocument;
use Asignua\FilamentSeoFiles\Data\LlmsLink;
use Asignua\FilamentSeoFiles\Data\LlmsSection;
use Asignua\FilamentSeoFiles\Data\SitemapEntry;

class CatalogSource implements LlmsFullSource, LlmsIndexSource, SitemapSource
{
    public function sitemapEntries(): iterable
    {
        foreach (Product::query()->lazyById() as $product) {
            yield new SitemapEntry(
                url: "https://shop.test/p/{$product->slug}",                 // the default language
                alternates: ['en' => "https://shop.test/p/{$product->slug}",
                             'uk' => "https://shop.test/uk/p/{$product->slug}"],
                lastModified: $product->updated_at,                          // optional
            );
        }
    }

    public function llmsSections(string $locale): iterable
    {
        yield new LlmsSection('Catalogue', [
            new LlmsLink('All products', 'https://shop.test/p', 'The full catalogue'),
        ]);
    }

    public function llmsDocuments(string $locale): iterable
    {
        yield new LlmsDocument('Delivery', 'https://shop.test/delivery', "# Delivery\n\nWe ship worldwide.");
    }
}

SeoFiles::ownedPathUsing(fn (string $locale, string $path): bool => Page::query()->where('slug', $path)->exists());

SeoFiles::robotsTemplateUsing(fn (string $baseUrl, string $default): string => $default."\nDisallow: /admin");

// config/filament-seo-files.php
'routes' => ['register' => false],

// routes/web.php
use Asignua\FilamentSeoFiles\SeoFiles;

SeoFiles::routes();            // before the catch-all
Route::get('/{path?}', …)->where('path', '.*');

// config/filament-seo-files.php
'schedule' => [
    'enabled' => true,
    'times' => ['sitemap' => '04:00', 'llms' => '04:20'],
],

$panel->plugin(SeoFilesPlugin::make()
    ->authorize(fn (): bool => auth()->user()?->isAdmin())
    ->navigationGroup('SEO')
    ->navigationSort(20));

use Asignua\FilamentSeoFiles\Actions\EditLlmsAction;
use Asignua\FilamentSeoFiles\Actions\EditRobotsAction;
use Asignua\FilamentSeoFiles\Actions\GenerateLlmsAction;
use Asignua\FilamentSeoFiles\Actions\GenerateSitemapAction;

public function generateSitemapAction(): Action { return GenerateSitemapAction::make(); }
public function editRobotsAction(): Action { return EditRobotsAction::make(); }
public function generateLlmsAction(): Action { return GenerateLlmsAction::make(); }
public function editLlmsAction(): Action { return EditLlmsAction::make(); }
bash
php artisan vendor:publish --tag="filament-seo-files-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="filament-seo-files-config"
php artisan vendor:publish --tag="filament-seo-files-translations"
bash
php artisan filament:assets