PHP code example of programmerhasan / seo

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

    

programmerhasan / seo example snippets


use ProgrammerHasan\Seo\Facades\Seo;

Seo::title('Laravel SEO Package')
    ->description('A lightweight SEO toolkit for Laravel.')
    ->canonical(url()->current())
    ->image(asset('images/og.jpg'));

$html = Seo::make()
    ->title('Best Laravel SEO Toolkit')
    ->description('Modern SEO package for Laravel, Inertia and APIs.')
    ->canonical('https://example.com/packages/seo')
    ->image('https://example.com/images/seo-og.jpg')
    ->article(published: now()->toAtomString())
    ->generate();

Seo::title('Page title');
Seo::description('Page description');
Seo::keywords(['laravel', 'seo', 'schema']);
Seo::canonical('https://example.com/page');
Seo::author('Programmer Hasan');
Seo::robots('index, follow');

Seo::noIndex();
Seo::noFollow();

Seo::title('Product page')
    ->description('Product description')
    ->image('https://example.com/product.jpg')
    ->type('product')
    ->og('locale', 'en_US')
    ->og('site_name', 'Example Store');

Seo::twitter('card', 'summary_large_image')
    ->twitter('site', '@yourhandle')
    ->twitter('creator', '@programmerhasan');

$schema = Seo::schema();

Seo::make()
    ->title('SEO Toolkit')
    ->schema($schema->product(
        name: 'SEO Toolkit',
        description: 'Laravel SEO package',
        image: 'https://example.com/product.jpg',
        sku: 'SEO-001',
        offers: $schema->offer('49', 'USD')
    ))
    ->generate();

Seo::schema()->organization('Example', 'https://example.com');
Seo::schema()->website('Example', 'https://example.com');
Seo::schema()->person('Programmer Hasan');
Seo::schema()->article('Title', 'https://example.com/post');
Seo::schema()->blogPosting('Title', 'https://example.com/post');
Seo::schema()->newsArticle('Title', 'https://example.com/news');
Seo::schema()->product('Product name');
Seo::schema()->offer('49', 'USD');
Seo::schema()->aggregateRating(4.8, 120);
Seo::schema()->review('Great product', 'Hasan', 5);
Seo::schema()->faq([['question' => 'Question?', 'answer' => 'Answer.']]);
Seo::schema()->breadcrumb([['name' => 'Home', 'url' => '/']]);
Seo::schema()->event('Laravel Meetup', '2026-05-12');
Seo::schema()->course('Laravel SEO', 'Learn SEO for Laravel');
Seo::schema()->howTo('How to install', ['Install package', 'Publish config']);
Seo::schema()->recipe('Recipe name', ['Ingredient'], ['Step 1']);
Seo::schema()->videoObject('Video title', 'Description', 'thumb.jpg', '2026-05-12');
Seo::schema()->softwareApplication('App name');

return Inertia::render('Posts/Show', [
    'post' => $post,
    'seo' => Seo::make()
        ->title($post->title)
        ->description($post->excerpt)
        ->canonical(route('posts.show', $post))
        ->forInertia(),
]);

Seo::fromModel($post)->generate();

Seo::autoCanonical();

Seo::alternate('en', 'https://example.com/en/page');
Seo::alternate('bn', 'https://example.com/bn/page');
Seo::alternate('x-default', 'https://example.com/page');

Seo::pagination($posts);

$xml = Seo::sitemap()
    ->add('https://example.com')
    ->add('https://example.com/about')
    ->image('https://example.com/post', [
        'https://example.com/image.jpg'
    ])
    ->video('https://example.com/video', [
        ['title' => 'Demo video']
    ])
    ->news('https://example.com/news', [
        'name' => 'Example News',
        'language' => 'en',
        'title' => 'News title',
    ])
    ->toXml();

Seo::sitemap()
    ->add('https://example.com')
    ->save(public_path('sitemap.xml'));

Seo::sitemap()
    ->index('https://example.com/sitemap-posts.xml')
    ->index('https://example.com/sitemap-products.xml')
    ->save(public_path('sitemap.xml'));

$content = Seo::robots()
    ->allow('/')
    ->disallow('/admin')
    ->sitemap('https://example.com/sitemap.xml')
    ->toString();

Seo::preload('/fonts/app.woff2', as: 'font', type: 'font/woff2', crossorigin: true);

Seo::preconnect('https://fonts.googleapis.com');

Seo::dnsPrefetch('https://cdn.example.com');

Seo::ai()->generate($content);

Seo::ai()->improve($content);

Seo::ai()->analyze($content, 'laravel seo');
bash
php artisan vendor:publish --tag=seo-config
bash
php artisan vendor:publish --tag=seo-views
bash
php artisan seo:sitemap
bash
php artisan seo:robots
bash
php artisan seo:install
php artisan seo:sitemap
php artisan seo:robots
php artisan seo:audit