yarmat / laravel-seo
dev-master
2019-01-20 06:10 UTC
Requires
- php: >=7.0
This package is auto-updated.
Last update: 2023-11-16 16:53:14 UTC
README
用于在Eloquent模型中使用SEO字段(标题,描述,关键词)的包。
安装
composer require yarmat/laravel-seo
您必须使用以下命令发布迁移
php artisan vendor:publish --provider="Yarmat\Seo\SeoServiceProvider" --tag="migrations"
迁移发布后,您可以通过运行迁移来创建seos-tables
php artisan migrate
使用方法
首先,将Yarmat\Seo\Traits\HasSeoTrait特质添加到您的模型中
use Illuminate\Database\Eloquent\Model; use Yarmat\Seo\Traits\HasSeoTrait; class Blog extends Model { use HasSeoTrait; }
可以添加SEO字段到模型中
$blog->saveSeo([ 'title' => 'Title', 'description' => 'Description', 'keywords' => 'Keywords' ]);
可以从模型中删除SEO字段
$blog->deleteSeo();
获取SEO字段
$blog->seo->title; // if seo.title not added to this model returned null $blog->seo->description; // if seo.description not added to this model returned null $blog->seo->keywords; // if seo.keywords not added to this model returned null
如果您想使用自己的模型
您必须使用以下命令发布配置
php artisan vendor:publish --provider="Yarmat\Seo\SeoServiceProvider" --tag="config"
发布后,编辑配置文件seo.php
return [ 'model' => App\Seo.php // f.e. ];
扩展您的模型
use Yarmat\Seo\Models\Seo as Model; class Seo extends Model { }
许可证
Laravel-seo是开源软件,遵循MIT许可证。