mb4it/laravel-seo
最新稳定版本:1.0.0
Composer 安装命令:
composer require mb4it/laravel-seo
包简介
Reusable SEO package for Laravel models with locale-aware polymorphic SEO entries.
关键字:
README 文档
README
Reusable Laravel SEO package for any Eloquent model via UseSeo trait.
Features
- Locale-aware SEO records in separate
seo_entriestable (polymorphic relation). - Configurable SEO fields with type map.
- Model-level SEO templates with placeholders (
{name},{description}). - Artisan command for adding new physical SEO columns with migration generation.
Installation
composer require mb4it/laravel-seo
Publish config and migrations:
php artisan vendor:publish --tag=laravel-seo-config php artisan vendor:publish --tag=laravel-seo-migrations php artisan migrate
Configure fields
config/seo.php supports two formats:
'fields' => ['h1', 'title']
All fields from list format default to string.
'fields' => [ 'h1' => 'string', 'title' => 'string', 'description' => 'text', 'image' => 'string', ]
Supported types: string, text, integer, boolean, json.
Use in model
use MB\Laravel\Seo\Concerns\UseSeo; class News extends Model { use UseSeo; }
Available API:
seoEntries(): MorphManyseo(?string $locale = null): MorphOne|MorphManysetSeo(array $data, ?string $locale = null): SeoEntrygetSeo(?string $locale = null): ?SeoEntry
SEO templates
If model defines seoTemplates(), templates are applied automatically after model save.
public function seoTemplates(): array { return [ 'h1' => '{name} - Site', 'description' => '{description}', ]; }
Rules:
- Placeholder format:
{attribute_name}. - Missing attributes are replaced with empty string.
- Explicitly saved SEO values (via
setSeo) are not overwritten by template values.
Add new SEO field (physical column)
Use command:
php artisan seo:add-field og_image string
What it does:
- Creates migration
*_add_og_image_to_seo_entries_table.php. - Tries to append
'og_image' => 'string'toconfig/seo.php.
Options:
--no-config- skip config file auto-update.
Example:
php artisan seo:add-field og_image string --no-config
统计信息
- 总下载量: 44
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-17