think.studio/nova-seo-entity
最新稳定版本:4.4.0
Composer 安装命令:
composer require think.studio/nova-seo-entity
包简介
Related entity to manage SEO data.
README 文档
README
Add to any model relation with SEO data.
| Nova | Package |
|---|---|
| V1 | V1,V2 |
| V4 | V3,V4 |
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
Credits
统计信息
- 总下载量: 26
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-03