Fluent SEO metadata service for Laravel with Open Graph, Twitter Card, and JSON-LD structured data support
composer require philiprehberger/laravel-seoFluent SEO metadata service for Laravel with Open Graph, Twitter Card, and JSON-LD structured data support.
composer require philiprehberger/laravel-seo
The service provider is registered automatically via Laravel package auto-discovery.
php artisan vendor:publish --tag=laravel-seo-config
This creates config/laravel-seo.php in your application.
php artisan vendor:publish --tag=laravel-seo-views
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"
/>
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);
use PhilipRehberger\Seo\Facades\Seo;
use PhilipRehberger\Seo\OgType;
Seo::setOgType(OgType::Article);
Seo::setOgType(OgType::Product);
Seo::setOgType(OgType::Video);
// Raw strings are still supported
Seo::setOgType('article');
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');
}
}
Seo::forPage('home');
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'],
]));
Seo::reset();
| 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(OgType|string $type) | Set the Open Graph type (enum or string) |
Seo::setOgImageAlt(string $alt) | Set the Open Graph image alt text |
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 |
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
If you find this project useful: