yaroslawww / nova-seo-entity

此包已被弃用且不再维护。作者建议使用think.studio/nova-seo-entity包。

用于管理SEO数据的关联实体。

4.4.0 2023-09-03 09:13 UTC

This package is auto-updated.

Last update: 2023-09-10 11:49:54 UTC


README

Packagist License Packagist Version Total Downloads Build Status Code Coverage Scrutinizer Code Quality

添加任何与SEO数据相关的模型关系。

Nova
V1 V1,V2
V4 V3,V4

安装

您可以通过composer安装此包

composer require think.studio/nova-seo-entity

# optional publish configs
php artisan vendor:publish --provider="NovaSeoEntity\ServiceProvider" --tag="config"
# as current package wrap "artesaos/seotools" package, will be useful publish internal config:
php artisan vendor:publish --provider="Artesaos\SEOTools\Providers\SEOToolsServiceProvider"

# publish translations
php artisan vendor:publish --provider="NovaSeoEntity\ServiceProvider" --tag="lang"

使用

添加SEO表

php artisan make:migration create_cms_seo_table
public function up()
{
    Schema::create(config('nova-seo-entity.table'), function (Blueprint $table) {
        \NovaSeoEntity\Database\MigrationHelper::defaultColumns($table);
    });
}

public function down()
{
    Schema::dropIfExists(config('nova-seo-entity.table'));
}

修改模型

class Article extends Model implements \NovaSeoEntity\Contracts\WithSeoEntity
{
    use \NovaSeoEntity\Models\Traits\HasSeoEntity;
    // ...
    
    /**
     * Example how set default value for nova "creation" screen
     */
    public function getNewInstanceSeoValueForDescription( ): ?string {
        return Str::limit( WysiwygHelper::html2Text( $this->content ), 150 );
    }
    
    /**
     * Override canonical value if not set
     */
    public function getSEOCanonicalFieldValue( mixed $value ): mixed {
        return $value ?: ($this->slug ? route( 'front.article.single', $this->slug ) : null);
    }

}

修改nova资源

向您的资源添加新字段

MorphOne::make('SEO', 'seo_info', SEOInfo::class),

修改应用程序服务提供者

您可以从包中添加资源或在其应用程序中扩展它。

// NovaServiceProvider.php
use NovaSeoEntity\Nova\Resources\SEOInfo;

public function boot() {
    // ...

    SEOInfo::morphToTypes([
        \App\Nova\Resources\CMS\Article::class,
        \App\Nova\Resources\CMS\Page::class
        // ...
    ]);

    parent::boot();
}

protected function resources() {
    parent::resources();
    // ...
    Nova::resources( [
        SEOInfo::class,
        // ...
    ] );
}

添加相关文件系统磁盘(或更改配置文件中的默认磁盘)

'cms-images'  => [
    'driver'     => 'local',
    'root'       => storage_path('app/public/cms-images'),
    'url'        => env('APP_URL').'/storage/cms-images',
    'visibility' => 'public',
],

显示元数据

<head>
    {!! \Artesaos\SEOTools\Facades\SEOTools::generate(!config('app.debug')) !!}
</head>

实现

$article = Article::find($articleId);

// Get seoinfo with default value
$article?->seo_info_forced->seoPrepare();

// Get seoinfo without defaults
// $article?->seo_info?->seoPrepare();

有用链接

Facebook: 分享 , 最佳实践. Facebook 调试器

Twitter: 摘要卡片 , 包含大图的摘要卡片 . Twitter 验证器

JsonLd: 简介 , 建议 , 图像许可证 , 示例

致谢

  • Think Studio