PHP code example of yaroslawww / nova-seo-entity

1. Go to this page and download the library: Download yaroslawww/nova-seo-entity library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yaroslawww / nova-seo-entity example snippets


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

}

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',
],

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

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

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