fabpl/laravel-seo
最新稳定版本:1.0.0
Composer 安装命令:
composer require fabpl/laravel-seo
包简介
A Laravel-native package to manage SEO-related HTML tags with precision and developer experience in mind.
README 文档
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
Seofacade - Supports standard SEO, Open Graph, and Twitter tags
- Automatically renders tags via the
@seoBlade 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\MetaTagsFabpl\Seo\Enums\OpenGraphTagsFabpl\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
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-11