laravel-seo maintained by mb4it
mb4it/laravel-seo
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