2017 © Pedro Peláez
 

library seotools

SEO Tools for Laravel and Lumen

image

tsawler/seotools

SEO Tools for Laravel and Lumen

  • Saturday, April 7, 2018
  • by tsawler
  • Repository
  • 1 Watchers
  • 1 Stars
  • 33 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 191 Forks
  • 0 Open issues
  • 28 Versions
  • 22 % Grown

The README.md

SEOTools - SEO Tools for Laravel and Lumen

SEOTools is a package for Laravel 5+ and Lumen that provides helpers for some common SEO techniques. This is forked from artesaos/seotools., (*1)

Features

  • Friendly Interface
  • Ease of set titles and meta tags
  • Ease of set metas for twitter and opengraph

Installation

1 - Dependency

The first step is using composer to install the package and automatically update your composer.json file, you can do this by running:, (*2)

composer require tsawler/seotools

Note: If you are using Laravel 5.5 or greater, the steps 2 and 3, for providers and aliases, are unnecessary. SEOTools supports Laravel new Package Discovery., (*3)

2 - Provider

You need to update your application configuration in order to register the package so it can be loaded by Laravel, just update your config/app.php file adding the following code at the end of your 'providers' section:, (*4)

config/app.php, (*5)

// file START ommited
    'providers' => [
        // other providers ommited
        Tsawler\SEOTools\Providers\SEOToolsServiceProvider::class,
    ],
// file END ommited

Lumen

Go to /bootstrap/app.php file and add this line:, (*6)

// file START ommited
    $app->register(Tsawler\SEOTools\Providers\SEOToolsServiceProvider::class);
// file END ommited

3 - Facade

Facades are not supported in Lumen., (*7)

In order to use the SEOMeta facade, you need to register it on the config/app.php file, you can do that the following way:, (*8)

// file START ommited
    'aliases' => [
        // other Facades ommited
        'SEOMeta'   => Tsawler\SEOTools\Facades\SEOMeta::class,
        'OpenGraph' => Tsawler\SEOTools\Facades\OpenGraph::class,
        'Twitter'   => Tsawler\SEOTools\Facades\TwitterCard::class,
        // or
        'SEO' => Tsawler\SEOTools\Facades\SEOTools::class,
    ],
// file END ommited

4 Configuration

Publish config

In your terminal type, (*9)

php artisan vendor:publish

or, (*10)

php artisan vendor:publish --provider="Tsawler\SEOTools\Providers\SEOToolsServiceProvider"

Lumen does not support this command, for it you should copy the file src/resources/config/seotools.php to config/seotools.php of your project, (*11)

In seotools.php configuration file you can determine the properties of the default values and some behaviors., (*12)

seotools.php

  • meta
    • defaults - What values are displayed if not specified any value for the page display. If the value is false, nothing is displayed.
    • webmaster - Are the settings of tags values for major webmaster tools. If you are null nothing is displayed.
  • opengraph
    • defaults - Are the properties that will always be displayed and when no other value is set instead. You can add additional tags that are not included in the original configuration file.
  • twitter
    • defaults - Are the properties that will always be displayed and when no other value is set instead. You can add additional tags that are not included in the original configuration file.

5 - Usage

Facades are not supported in Lumen., (*13)

Lumen Usage

$seotools = app('seotools');
$metatags = app('seotools.metatags');
$twitter = app('seotools.twitter');
$opengraph = app('seotools.opengraph');

// The behavior is the same as the facade
// --------

echo app('seotools')->generate();

Meta tags Generator

With SEOMeta you can create meta tags to the head, (*14)

Opengraph tags Generator

With OpenGraph you can create opengraph tags to the head, (*15)

Twitter for Twitter Cards tags Generator

With Twitter you can create opengraph tags to the head, (*16)

In your controller

use SEOMeta;
use OpenGraph;
use Twitter;
## or
use SEO;

class CommomController extends Controller
{

    /**
     * @return \Illuminate\View\View
     */
    public function index()
    {
        SEOMeta::setTitle('Home');
        SEOMeta::setDescription('This is my page description');
        SEOMeta::setCanonical('https://codecasts.com.br/lesson');

        OpenGraph::setDescription('This is my page description');
        OpenGraph::setTitle('Home');
        OpenGraph::setUrl('http://current.url.com');
        OpenGraph::addProperty('type', 'articles');

        Twitter::setTitle('Homepage');
        Twitter::setSite('@LuizVinicius73');

        ## Or

        SEO::setTitle('Home');
        SEO::setDescription('This is my page description');
        SEO::opengraph()->setUrl('http://current.url.com');
        SEO::setCanonical('https://codecasts.com.br/lesson');
        SEO::opengraph()->addProperty('type', 'articles');
        SEO::twitter()->setSite('@LuizVinicius73');

        $posts = Post::all();

        return view('myindex', compact('posts'));
    }

    /**
     * @return \Illuminate\View\View
     */
    public function show($id)
    {
        $post = Post::find($id);

        SEOMeta::setTitle($post->title);
        SEOMeta::setDescription($post->resume);
        SEOMeta::addMeta('article:published_time', $post->published_date->toW3CString(), 'property');
        SEOMeta::addMeta('article:section', $post->category, 'property');
        SEOMeta::addKeyword(['key1', 'key2', 'key3']);

        OpenGraph::setDescription($post->resume);
        OpenGraph::setTitle($post->title);
        OpenGraph::setUrl('http://current.url.com');
        OpenGraph::addProperty('type', 'article');
        OpenGraph::addProperty('locale', 'pt-br');
        OpenGraph::addProperty('locale:alternate', ['pt-pt', 'en-us']);

        OpenGraph::addImage($post->cover->url);
        OpenGraph::addImage($post->images->list('url'));
        OpenGraph::addImage(['url' => 'http://image.url.com/cover.jpg', 'size' => 300]);
        OpenGraph::addImage('http://image.url.com/cover.jpg', ['height' => 300, 'width' => 300]);

        // Namespace URI: http://ogp.me/ns/article#
        // article
        OpenGraph::setTitle('Article')
            ->setDescription('Some Article')
            ->setType('article')
            ->setArticle([
                'published_time' => 'datetime',
                'modified_time' => 'datetime',
                'expiration_time' => 'datetime',
                'author' => 'profile / array',
                'section' => 'string',
                'tag' => 'string / array'
            ]);

        // Namespace URI: http://ogp.me/ns/book#
        // book
        OpenGraph::setTitle('Book')
            ->setDescription('Some Book')
            ->setType('book')
            ->setBook([
                'author' => 'profile / array',
                'isbn' => 'string',
                'release_date' => 'datetime',
                'tag' => 'string / array'
            ]);

        // Namespace URI: http://ogp.me/ns/profile#
        // profile
        OpenGraph::setTitle('Profile')
             ->setDescription('Some Person')
            ->setType('profile')
            ->setProfile([
                'first_name' => 'string',
                'last_name' => 'string',
                'username' => 'string',
                'gender' => 'enum(male, female)'
            ]);

        // Namespace URI: http://ogp.me/ns/music#
        // music.song
        OpenGraph::setType('music.song')
            ->setMusicSong([
                'duration' => 'integer',
                'album' => 'array',
                'album:disc' => 'integer',
                'album:track' => 'integer',
                'musician' => 'array'
            ]);

        // music.album
        OpenGraph::setType('music.album')
            ->setMusicAlbum([
                'song' => 'music.song',
                'song:disc' => 'integer',
                'song:track' => 'integer',
                'musician' => 'profile',
                'release_date' => 'datetime'
            ]);

         //music.playlist
        OpenGraph::setType('music.playlist')
            ->setMusicPlaylist([
                'song' => 'music.song',
                'song:disc' => 'integer',
                'song:track' => 'integer',
                'creator' => 'profile'
            ]);

        // music.radio_station
        OpenGraph::setType('music.radio_station')
            ->setMusicRadioStation([
                'creator' => 'profile'
            ]);

        // Namespace URI: http://ogp.me/ns/video#
        // video.movie
        OpenGraph::setType('video.movie')
            ->setVideoMovie([
                'actor' => 'profile / array',
                'actor:role' => 'string',
                'director' => 'profile /array',
                'writer' => 'profile / array',
                'duration' => 'integer',
                'release_date' => 'datetime',
                'tag' => 'string / array'
            ]);

        // video.episode
        OpenGraph::setType('video.episode')
            ->setVideoEpisode([
                'actor' => 'profile / array',
                'actor:role' => 'string',
                'director' => 'profile /array',
                'writer' => 'profile / array',
                'duration' => 'integer',
                'release_date' => 'datetime',
                'tag' => 'string / array',
                'series' => 'video.tv_show'
            ]);

        // video.tv_show
        OpenGraph::setType('video.tv_show')
            ->setVideoTVShow([
                'actor' => 'profile / array',
                'actor:role' => 'string',
                'director' => 'profile /array',
                'writer' => 'profile / array',
                'duration' => 'integer',
                'release_date' => 'datetime',
                'tag' => 'string / array'
            ]);

        // video.other
        OpenGraph::setType('video.other')
            ->setVideoOther([
                'actor' => 'profile / array',
                'actor:role' => 'string',
                'director' => 'profile /array',
                'writer' => 'profile / array',
                'duration' => 'integer',
                'release_date' => 'datetime',
                'tag' => 'string / array'
            ]);

        // og:video
        OpenGraph::addVideo('http://example.com/movie.swf', [
                'secure_url' => 'https://example.com/movie.swf',
                'type' => 'application/x-shockwave-flash',
                'width' => 400,
                'height' => 300
            ]);

        // og:audio
        OpenGraph::addAudio('http://example.com/sound.mp3', [
                'secure_url' => 'https://secure.example.com/sound.mp3',
                'type' => 'audio/mpeg'
            ]);

        return view('myshow', compact('post'));
    }
}

SEOTrait

use Tsawler\SEOTools\Traits\SEOTools as SEOToolsTrait;

class CommomController extends Controller
{
    use SEOToolsTrait;

    /**
     * @return \Illuminate\View\View
     */
    public function index()
    {
        $this->seo()->setTitle('Home');
        $this->seo()->setDescription('This is my page description');
        $this->seo()->opengraph()->setUrl('http://current.url.com');
        $this->seo()->opengraph()->addProperty('type', 'articles');
        $this->seo()->twitter()->setSite('@LuizVinicius73');

        $posts = Post::all();

        return view('myindex', compact('posts'));
    }
}

In Your View

Pro Tip: Pass the parameter true to get minified code and reduce filesize., (*17)

<html>
<head>
    {!! SEOMeta::generate() !!}
    {!! OpenGraph::generate() !!}
    {!! Twitter::generate() !!}
        <!-- OR -->
    {!! SEO::generate() !!}

      <!-- MINIFIED -->
    {!! SEO::generate(true) !!}


        <!-- LUMEN -->
    {!! app('seotools')->generate() !!}
</head>
<body>

</body>
</html>
<html>
<head>
    <title>Title - Over 9000 Thousand!</title>
    <meta name='description' itemprop='description' content='description...' />
    <meta name='keywords' content='key1, key2, key3' />
    <meta property='article:published_time' content='2015-01-31T20:30:11-02:00' />
    <meta property='article:section' content='news' />

    <meta property="og:description"content="description..." />
    <meta property="og:title"content="Title" />
    <meta property="og:url"content="http://current.url.com" />
    <meta property="og:type"content="article" />
    <meta property="og:locale"content="pt-br" />
    <meta property="og:locale:alternate"content="pt-pt" />
    <meta property="og:locale:alternate"content="en-us" />
    <meta property="og:site_name"content="name" />
    <meta property="og:image"content="http://image.url.com/cover.jpg" />
    <meta property="og:image"content="http://image.url.com/img1.jpg" />
    <meta property="og:image"content="http://image.url.com/img2.jpg" />
    <meta property="og:image"content="http://image.url.com/img3.jpg" />
    <meta property="og:image:url"content="http://image.url.com/cover.jpg" />
    <meta property="og:image:size"content="300" />

    <meta name="twitter:card"content="summary" />
    <meta name="twitter:title"content="Title" />
    <meta name="twitter:site"content="@LuizVinicius73" />

</head>
<body>

</body>
</html>

API (SEOMeta)

SEOMeta::addKeyword($keyword);
SEOMeta::addMeta($meta, $value = null, $name = 'name');
SEOMeta::addAlternateLanguage($lang, $url);
SEOMeta::addAlternateLanguages(array $languages);
SEOMeta::setTitleSeparator($separator);
SEOMeta::setTitle($title);
SEOMeta::setTitleDefault($default);
SEOMeta::setDescription($description);
SEOMeta::setKeywords($keywords);
SEOMeta::setTitleSeparator($separator);
SEOMeta::setCanonical($url);
SEOMeta::setPrev($url);
SEOMeta::setNext($url);
SEOMeta::removeMeta($key);

// You can chain methods
SEOMeta::setTitle($title)
            ->setDescription($description)
            ->setKeywords($keywords)
            ->addKeyword($keyword)
            ->addMeta($meta, $value);

// Retrieving data
SEOMeta::getTitle();
SEOMeta::getTitleSession();
SEOMeta::getTitleSeparator();
SEOMeta::getKeywords();
SEOMeta::getDescription();
SEOMeta::getCanonical($url);
SEOMeta::getPrev($url);
SEOMeta::getNext($url);
SEOMeta::reset();

SEOMeta::generate();

API (OpenGraph)

OpenGraph::addProperty($key, $value); // value can be string or array
OpenGraph::addImage($url); // add image url
OpenGraph::addImages($url); // add an array of url images
OpenGraph::setTitle($title); // define title
OpenGraph::setDescription($description);  // define description
OpenGraph::setUrl($url); // define url
OpenGraph::setSiteName($name); //define site_name

// You can chain methods
OpenGraph::addProperty($key, $value)
            ->addImage($url)
            ->addImages($url)
            ->setTitle($title)
            ->setDescription($description)
            ->setUrl($url)
            ->setSiteName($name);

// Generate html tags
OpenGraph::generate();

API (TwitterCard)

Twitter::addValue($key, $value); // value can be string or array
Twitter::setType($type); // type of twitter card tag
Twitter::setTitle($type); // title of twitter card tag
Twitter::setSite($type); // site of twitter card tag
Twitter::setDescription($type); // description of twitter card tag
Twitter::setUrl($type); // url of twitter card tag
Twitter::addImage($url); // add image url
Twitter::addImages($url); // add an array of url images

// You can chain methods
Twitter::addValue($key, $value)
            ->setType($type)
            ->addImage($url)
            ->addImages($url)
            ->setTitle($title)
            ->setDescription($description)
            ->setUrl($url)
            ->setSite($name);

// Generate html tags
Twitter::generate();

API (SEO)

Facilitates access to all the SEO Providers, (*18)

SEO::metatags();
SEO::twitter();
SEO::opengraph();

SEO::setTitle($title);
SEO::getTitle($session = false);
SEO::setDescription($description);
SEO::setCanonical($url);
SEO::addImages($urls);

The Versions

07/04 2018

dev-master

9999999-dev

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar tsawler

lumen laravel5 seo opengraph webmaster metatags seotools

23/02 2018
23/02 2018
25/09 2017

v0.11.0-beta1

0.11.0.0-beta1

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

lumen laravel5 seo opengraph webmaster metatags seotools

25/09 2017

v0.11.1

0.11.1.0

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

lumen laravel5 seo opengraph webmaster metatags seotools

27/10 2016

v0.10.0

0.10.0.0

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

lumen laravel5 seo opengraph webmaster metatags seotools

30/04 2016

v0.9.2

0.9.2.0

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

lumen laravel5 seo opengraph webmaster metatags seotools

29/04 2016

v0.9.1

0.9.1.0

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

lumen laravel5 seo opengraph webmaster metatags seotools

25/03 2016

v0.9.0

0.9.0.0

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

lumen laravel5 seo opengraph webmaster metatags seotools

24/01 2016

v0.8.2

0.8.2.0

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

lumen laravel5 seo opengraph webmaster metatags seotools

07/01 2016

v0.8.1

0.8.1.0

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

lumen laravel5 seo opengraph webmaster metatags seotools

07/01 2016

v0.8.0

0.8.0.0

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

lumen laravel5 seo opengraph webmaster metatags seotools

04/12 2015

v0.7.4

0.7.4.0

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

lumen laravel5 seo opengraph webmaster metatags seotools

14/09 2015

v0.7.3.6

0.7.3.6

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

lumen laravel5 seo opengraph webmaster metatags seotools

28/07 2015

v0.7.3.5

0.7.3.5

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

lumen laravel5 seo opengraph webmaster metatags seotools

10/06 2015

v0.7.3.4

0.7.3.4

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

lumen laravel5 seo opengraph webmaster metatags seotools

26/05 2015

v0.7.3.3

0.7.3.3

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

lumen laravel5 seo opengraph webmaster metatags seotools

26/05 2015

v0.7.3.2

0.7.3.2

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

lumen laravel5 seo opengraph webmaster metatags seotools

30/04 2015

v0.7.3.1

0.7.3.1

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

lumen laravel5 seo opengraph webmaster metatags seotools

29/04 2015

v0.7.3

0.7.3.0

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

lumen laravel5 seo opengraph webmaster metatags seotools

29/04 2015

v0.7.2

0.7.2.0

SEO Tools for Laravel and Lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

lumen laravel5 seo opengraph webmaster metatags seotools

29/04 2015

v0.7.1

0.7.1.0

SEO Tools for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

laravel5 seo opengraph webmaster metatags seotools

17/03 2015

v0.6

0.6.0.0

SEO Tools for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

laravel5 seo opengraph webmaster metatags seotools

10/03 2015

0.4.1

0.4.1.0

SEO Tools for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

laravel5 seo opengraph webmaster metatags seotools

05/03 2015

0.4

0.4.0.0

SEO Tools for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

laravel5 seo opengraph webmaster metatags seotools

05/03 2015

0.4-beta

0.4.0.0-beta

SEO Tools for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

laravel5 seo opengraph webmaster metatags seotools

03/03 2015

0.3-beta

0.3.0.0-beta

SEO Tools for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius

laravel5 seo opengraph webmaster metatags seotools

03/03 2015

0.2-beta

0.2.0.0-beta

SEO Tools for Laravel

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Vinicius