Package for using seo fields (Title, Description, Keywords) in your Eloquent Model.
composer require yarmat/laravel-seo
You must publish the migration with:
php artisan vendor:publish --provider="Yarmat\Seo\SeoServiceProvider" --tag="migrations"
After the migration has been published you can create seos-tables by running the migrations:
php artisan migrate
First, add the Yarmat\Seo\Traits\HasSeoTrait trait to your model(s):
use Illuminate\Database\Eloquent\Model; use Yarmat\Seo\Traits\HasSeoTrait; class Blog extends Model { use HasSeoTrait; }
A Seo fields can be added to your model:
$blog->saveSeo([ 'title' => 'Title', 'description' => 'Description', 'keywords' => 'Keywords' ]);
A Seo fields can be deleted from your model:
$blog->deleteSeo();
Get the Seo fields
$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
You must publish the config with:
php artisan vendor:publish --provider="Yarmat\Seo\SeoServiceProvider" --tag="config"
After publishing edit config file seo.php
return [ 'model' => App\Seo.php // f.e. ];
Extend your model
use Yarmat\Seo\Models\Seo as Model; class Seo extends Model { }
The Laravel-seo is open-sourced software licensed under the MIT license.