mb4it/laravel-seo

Reusable SEO package for Laravel models with locale-aware polymorphic SEO entries.

Maintainers

Package info

github.com/Dictator90/laravel-seo

pkg:composer/mb4it/laravel-seo

Statistics

Installs: 4

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-04-17 11:51 UTC

This package is auto-updated.

Last update: 2026-04-17 11:53:03 UTC


README

Reusable Laravel SEO package for any Eloquent model via UseSeo trait.

Features

  • Locale-aware SEO records in separate seo_entries table (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(): MorphMany
  • seo(?string $locale = null): MorphOne|MorphMany
  • setSeo(array $data, ?string $locale = null): SeoEntry
  • getSeo(?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:

  1. Creates migration *_add_og_image_to_seo_entries_table.php.
  2. Tries to append 'og_image' => 'string' to config/seo.php.

Options:

  • --no-config - skip config file auto-update.

Example:

php artisan seo:add-field og_image string --no-config