Looking to hire Laravel developers? Try LaraJobs

laravel-seo maintained by philiprehberger

Description
Fluent SEO metadata service for Laravel with Open Graph, Twitter Card, and JSON-LD structured data support
Last update
2026/04/22 18:22 (dev-main)
License
Downloads
53

Comments
comments powered by Disqus

Laravel SEO

Tests Latest Version on Packagist License

Fluent SEO metadata service for Laravel with Open Graph, Twitter Card, and JSON-LD structured data support.

Requirements

  • PHP 8.2+
  • Laravel 11 or 12

Installation

composer require philiprehberger/laravel-seo

Publish the config file

php artisan vendor:publish --tag=laravel-seo-config

This creates config/laravel-seo.php in your application.

Optionally publish the Blade views

php artisan vendor:publish --tag=laravel-seo-views

Usage

Blade Component

Add the <x-seo::meta /> component inside your layout's <head> tag:

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <x-seo::meta />
</head>

The component reads all values from the SeoService singleton, but also accepts inline overrides:

<x-seo::meta
    title="Custom Title"
    description="Custom description"
    canonical="https://example.com/page"
    ogImage="https://example.com/og.jpg"
    ogType="article"
    :noindex="true"
/>

Fluent API via Facade

use PhilipRehberger\Seo\Facades\Seo;

Seo::setTitle('My Page')
   ->setDescription('Welcome to my page.')
   ->setCanonical('https://example.com/page')
   ->setOgImage('https://example.com/og.jpg')
   ->setOgType('article')
   ->setNoindex(false);

Service Injection

use PhilipRehberger\Seo\SeoService;

class PageController extends Controller
{
    public function show(SeoService $seo): View
    {
        $seo->setTitle('About Us')
            ->setDescription('Learn about our team.');

        return view('about');
    }
}

Page-Specific SEO from Config

Seo::forPage('home');

JSON-LD Structured Data

Seo::addJsonLd([
    '@context' => 'https://schema.org',
    '@type'    => 'Article',
    'headline' => 'My Blog Post',
]);

// Built-in schema generators
Seo::addJsonLd(Seo::getOrganizationSchema());
Seo::addJsonLd(Seo::getWebsiteSchema());
Seo::addJsonLd(Seo::getServiceSchema('Web Design', 'We design beautiful websites.', 'Design'));
Seo::addJsonLd(Seo::getBreadcrumbSchema([
    ['name' => 'Home', 'url' => 'https://example.com/'],
    ['name' => 'Blog', 'url' => 'https://example.com/blog'],
]));

Resetting Between Requests

Seo::reset();

API

Method Description
Seo::setTitle(string $title) Set the page title
Seo::setDescription(string $description) Set the meta description
Seo::setCanonical(string $url) Set the canonical URL
Seo::setOgImage(string $url) Set the Open Graph image
Seo::setOgType(string $type) Set the Open Graph type
Seo::setNoindex(bool $noindex) Set the noindex flag
Seo::forPage(string $key) Load SEO data from config for a page key
Seo::addJsonLd(array $schema) Add a JSON-LD structured data block
Seo::getOrganizationSchema() Generate an Organization schema array
Seo::getWebsiteSchema() Generate a WebSite schema array
Seo::getServiceSchema(string $name, string $description, string $type) Generate a Service schema array
Seo::getBreadcrumbSchema(array $items) Generate a BreadcrumbList schema array
Seo::reset() Reset the service state

Development

composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse

License

MIT