yaroslawww/nova-seo-entity

Related entity to manage SEO data.

1.0.2 2021-10-17 10:58 UTC

This package is auto-updated.

Last update: 2021-11-17 11:08:49 UTC


README

Packagist License Packagist Version Build Status Code Coverage Scrutinizer Code Quality

Add to any model relation with SEO data.

Installation

You can install the package via composer:

composer require yaroslawww/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"

Usage

Add seo table

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'));
}

Amend models

use NovaSeoEntity\Contracts\WithSeoEntity;
use NovaSeoEntity\Models\Traits\HasSeoEntity;

class Article extends Model extends WithSeoEntity
{
    use 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);
    }

}

Amend nova resource

Add new field to your resource

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

Amend app service provider

You can add resource from package or extend it in your app.

// 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,
        // ...
    ] );
}

Display meta data

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

Useful links

Facebook: sharing , best practices. Facebook debuger

Twitter: summary card , summary card with large image . Twitter validator

JsonLd: intro , recommendations , image license , example

Credits

  • Think Studio