fomvasss / laravel-seo
Laravel SEO package
Installs: 1 064
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: ^8.0
- illuminate/contracts: ^9|^10|^11
README
With this package you can manage meta-tags and SEO-fields from Laravel app.
Installation
You can install the package via composer:
composer require fomvasss/laravel-seo
You can publish and run the migrations with:
php artisan vendor:publish --provider="Fomvasss\Seo\SeoServiceProvider"
php artisan migrate
Usage
The Eloquent model must has the Trait HasSeo
:
namespace App\Models; use Fomvasss\Seo\Models\HasSeo; class PostModel extends Model { use HasSeo; //... public function registerSeoDefaultTags(): array { return [ 'title' => $this->name, 'description' => $this->description, 'og_image' => $this->getFirstMediaUrl('images', 'thumb'), ]; } }
Also in model you can define default tags in method registerSeoDefaultTags
Allowed next methods (By increasing priority):
Seo::setDefault(['title' => 'Blog']); Seo::setModel($post); Seo::setPath('page/faq'); Seo::setTags(['keywords' => 'Laravel, SEO, tags']);
Rendering tags in Blade (in HTML head):
{!! \Seo::setGroup(app()->getLocale()) ->setDefault([ 'og_site_name' => config('app.name'), 'og_url' => URL::full(), 'og_locale' => app()->getLocale(), ])->renderHtml() !!}
Get array tags (for API resource, etc.):
\Seo::setGroup(app()->getLocale()) ->setDefault([ 'og_site_name' => config('app.name'), 'og_locale' => app()->getLocale(), ])->getTags();
You can save tags for model in DB:
$post->seo('uk')->updateOrCreate([], ['tags' => ['title' => 'Hello Page', 'description' => 'Lorem Ipsum'], 'group' => 'uk']);
And get tags (for edit) for dashboard:
$tags = $post->getRawSeoTags('uk');
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.