mb4it/laravel-seo 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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_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

统计信息

  • 总下载量: 44
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固