think.studio / nova-seo-entity
Related entity to manage SEO data.
4.4.0
2023-09-03 09:13 UTC
Requires
- php: ^8.1
- artesaos/seotools: ^1.0
- laravel/nova: ^4.13
- think.studio/laravel-simple-image-manager: ^3.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.21
- orchestra/testbench: ^8.5
- phpunit/phpunit: ^10.2
- psalm/plugin-laravel: ^2.8
- vimeo/psalm: ^5.13
README
Add to any model relation with SEO data.
Installation
You can install the package via 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"
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
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); } }
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, // ... ] ); }
Add related filesystem disk (or change default disc in config file)
'cms-images' => [ 'driver' => 'local', 'root' => storage_path('app/public/cms-images'), 'url' => env('APP_URL').'/storage/cms-images', 'visibility' => 'public', ],
Display meta data
<head> {!! \Artesaos\SEOTools\Facades\SEOTools::generate(!config('app.debug')) !!} </head>
Implement
$article = Article::find($articleId); // Get seoinfo with default value $article?->seo_info_forced->seoPrepare(); // Get seoinfo without defaults // $article?->seo_info?->seoPrepare();
Useful links
Facebook: sharing , best practices. Facebook debuger
Twitter: summary card , summary card with large image . Twitter validator
JsonLd: intro , recommendations , image license , example