fabpl / laravel-seo
A Laravel-native package to manage SEO-related HTML tags with precision and developer experience in mind.
1.0.0
2025-07-11 10:32 UTC
Requires
- php: ^8.2
- illuminate/contracts: ^12.0
Requires (Dev)
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1
- orchestra/testbench: ^10.0.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
README
A Laravel-native package to manage SEO-related HTML tags with precision and developer experience in mind.
Supports title
, meta
, og:*
, twitter:*
, and canonical
tags โ nothing more, nothing less.
โจ Features
- Fluent, expressive API via a
Seo
facade - Supports standard SEO, Open Graph, and Twitter tags
- Automatically renders tags via the
@seo
Blade directive - Enum-based tag validation for strict SEO compliance
- Default fallback values via
config/seo.php
- Auto-injects
<link rel="canonical">
(optional)
๐ Installation
composer require fabpl/laravel-seo
Publish the config file:
php artisan vendor:publish --tag=seo-config
โ๏ธ Configuration
Edit the config/seo.php
file to set global defaults:
return [ /* |-------------------------------------------------------------------------- | Default Title |-------------------------------------------------------------------------- | | This title will be used if no title is explicitly set via Seo::title(). | */ 'title' => env('APP_NAME', 'Laravel'), /* |-------------------------------------------------------------------------- | Default Meta Tags |-------------------------------------------------------------------------- | | Meta tags that should be included by default on all pages. | Only tags defined in MetaTags enum are supported. | */ 'meta' => [ 'author' => '', 'description' => '', 'keywords' => '', 'robots' => 'index, follow', ], /* |-------------------------------------------------------------------------- | Default Open Graph Tags |-------------------------------------------------------------------------- | | Open Graph tags included on all pages. Keys must match values from | the OpenGraphTags enum. | */ 'open_graph' => [ 'og:description' => '', 'og:image' => '', 'og:locale' => env('APP_LOCALE', 'en'), 'og:site_name' => env('APP_NAME', 'Laravel'), 'og:title' => env('APP_NAME', 'Laravel'), 'og:type' => 'website', ], /* |-------------------------------------------------------------------------- | Default Twitter Tags |-------------------------------------------------------------------------- | | Twitter card tags included by default. Keys must match values from | the TwitterTags enum. | */ 'twitter' => [ 'twitter:card' => 'summary_large_image', 'twitter:creator' => '', // e.g. '@username' 'twitter:description' => '', 'twitter:image' => '', 'twitter:site' => '', // e.g. '@yourhandle' 'twitter:title' => env('APP_NAME', 'Laravel'), ], /* |-------------------------------------------------------------------------- | Auto Canonical URL |-------------------------------------------------------------------------- | | When enabled, the current URL will be automatically added as a canonical | tag unless manually overridden via Seo::canonical(). | */ 'auto_canonical' => true, ];
โ Usage
In a controller:
use Fabpl\Seo\Facades\Seo; use Fabpl\Seo\Enums\MetaTags; use Fabpl\Seo\Enums\OpenGraphTags; use Fabpl\Seo\Enums\TwitterTags; Seo::title('Laravel Seo Package') ->description('A Laravel-native package to manage SEO-related HTML tags with precision and developer experience in mind.') ->twitter(TwitterTags::Creator, '@fabpl') ->canonical('https://github.com/fabpl/laravel-seo');
In a Blade layout:
<head> ... @seo </head>
๐ Strict SEO Tag Validation
Only officially supported SEO tags are allowed. All supported keys are defined as PHP enum
classes:
Fabpl\Seo\Enums\MetaTags
Fabpl\Seo\Enums\OpenGraphTags
Fabpl\Seo\Enums\TwitterTags
Invalid keys throw exception.
๐ฆ API Reference
Seo::title(string $title): self;
Seo::description(string $description): self;
Seo::keywords(array $keywords): self;
Seo::author(string $author): self;
Seo::canonical(string $url): self;
Seo::meta(MetaTags $name, string $content): self;
Seo::openGraph(OpenGraphTags $name, string $content): self;
Seo::twitter(TwitterTags $name, string $content): self;
Seo::render(): HtmlString;
๐งช Testing
Tests are included and can be run with:
composer test
๐ License
MIT ยฉ Fabrice