2017 © Pedro Peláez
 

library laravel-seo-meta

Laravel seo meta

image

am2studio/laravel-seo-meta

Laravel seo meta

  • Wednesday, October 25, 2017
  • by msamec
  • Repository
  • 6 Watchers
  • 2 Stars
  • 3,972 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 3 % Grown

The README.md

Laravel-Seo Meta

Package for handling seo meta tags in Laravel apps, (*1)

Install

Via Composer, (*2)

``` bash $ composer require am2studio/laravel-seo-meta, (*3)


## Usage First run migration for this package (src/migration/): ```php 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", (*4)

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()", (*5)

seoMetasConfig() is configuration for meta data for model, (*6)

seoMetas() is "hasMany" relation to seoMetas of model, (*7)

public function seoMetasConfig()
{
    return [
        'title'         => ['generator' => 'example.com - '. $this->title],
        'description'   => ['generator' => 'green-rush.com - '. $this->title . ' - ' . $this->short_description,],
        'keywords'      => ['generator' => 'greenrush, product, ' . $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:, (*8)

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), (*9)

Finaly add "seoMeta" to Model -> fillable, (*10)

protected $fillable = [
    ...
    'seoMeta'
];

Show form for meta seo deta on model:, (*11)

{!! \AM2Studio\Laravel\SeoMeta\SeoMetaHelper::form($product) !!}

Set data in controller:, (*12)


public function __construct() { parent::__construct(); SeoMetaHelper::setSeoMeta(['title' => 'Default title __construct .']); } public function index() { SeoMetaHelper::setSeoMeta(['description' => 'Default description index .']); return $this->view('index'); } public function show($product) { SeoMetaHelper::setSeoMeta($product->getSeoMeta()); return $this->view('show', compact('product')); }

Show meta in view :, (*13)

{{
    \AM2Studio\Laravel\SeoMeta\SeoMetaHelper::render([
        //alternative data if is not set anywhere
        'keywords' => 'example.com -> frontend layout'
    ])
}}

Change log

Please see CHANGELOG for more information what has changed recently., (*14)

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*15)

License

The MIT License (MIT). Please see License File for more information., (*16)

The Versions

25/10 2017

dev-master

9999999-dev https://github.com/AM2studio/Laravel-SeoMeta

Laravel seo meta

  Sources   Download

MIT

The Requires

 

am2studio laravel seo meta

21/03 2016

1.0.4

1.0.4.0 https://github.com/AM2studio/Laravel-SeoMeta

Laravel seo meta

  Sources   Download

MIT

The Requires

 

am2studio laravel seo meta

11/03 2016

1.0.3

1.0.3.0 https://github.com/AM2studio/Laravel-SeoMeta

Laravel seo meta

  Sources   Download

MIT

The Requires

 

am2studio laravel seo meta

23/02 2016

1.0.2

1.0.2.0 https://github.com/AM2studio/Laravel-SeoMeta

Laravel seo meta

  Sources   Download

MIT

The Requires

 

am2studio laravel seo meta

23/02 2016

1.0.1

1.0.1.0 https://github.com/AM2studio/Laravel-SeoMeta

Laravel seo meta

  Sources   Download

MIT

The Requires

 

am2studio laravel seo meta

22/02 2016

1.0.0

1.0.0.0 https://github.com/AM2studio/Laravel-SeoMeta

Laravel seo meta

  Sources   Download

MIT

The Requires

 

am2studio laravel seo meta