Package Data | |
---|---|
Maintainer Username: | lostcause |
Maintainer Contact: | filip.horvat@am2studio.hr (Filip Horvat) |
Package Create Date: | 2016-02-25 |
Package Last Update: | 2016-02-25 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:11:46 |
Package Statistics | |
---|---|
Total Downloads: | 6 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Package for handling seo meta tags in Laravel apps
Via Composer
$ composer require am2studio/laravel-seo-meta
First run migration for this package (src/migration/):
Schema::create('seo_metas', function (Blueprint $table) {
$table->increments('id');
$table->string('model_type');
$table->integer('model_id')->unsigned();
$table->text('key');
$table->text('value');
$table->timestamps();
});
For each model which that use seo meta add trait "SeoMetaTrait" and implement interface "SeoMetaInterface"
use AM2Studio\Laravel\SeoMeta\SeoMetaTrait;
use AM2Studio\Laravel\SeoMeta\SeoMetaInterface;
class User implements SeoMetaInterface
{
use SeoMetaTrait;
Interface "SeoMetaInterface" have 2 function that model need to implement "seoMetasConfig()" and "seoMetas()"
seoMetasConfig() is configuration for meta data for model
seoMetas() is "hasMany" relation to seoMetas of model
public function seoMetasConfig()
{
return [
'title' => ['generator' => 'example.com - '. $this->title],
'description' => ['generator' => 'green-rush.com - '. $this->title . ' - ' . $this->short_description,],
'keywords' => ['generator' => 'greenrush, dispensary, ' . $this->title . ', ' . $this->short_description,
'edit'=> false],
'og:image' => ['generator' => ["http://i.stack.imgur.com/hEobN.jpg", "http://i.stack.imgur.com/hEobN2.jpg"]],
'twitter:site' => [],
];
}
public function seoMetas()
{
return $this->hasMany(SeoMeta::class, 'model_id')->where(['model_type' => __CLASS__]);
}
Each seo meta that you want model to use must be fefined here. List of possible seo meta tags:
title -> string
description -> string
keywords -> string
canonical -> string
article:published_time -> string
article:section -> string
og:description -> string
og:title -> string
og:url -> string
og:type -> string
og:locale -> string
og:locale:alternate -> array
og:site_name -> string
og:image -> array
og:image:url -> array
og:image:size -> string
twitter:card -> string
twitter:title -> string
twitter:site -> string
For each seo meta in config you define generator(how seo meta will be generated) and edit (if seo meta can be edited or will be always generated on model save, default - true)
Show form for meta seo deta on model:
{!! \AM2Studio\Laravel\SeoMeta\SeoMetaHelper::form($dispensary) !!}
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING and CONDUCT for details.
The MIT License (MIT). Please see License File for more information.