Laravel SEO tools

There are hundreds of SEO tools available on the internet. These SEO tools are widely used by the SEOs to make their websites rank higher in search engine results. These tools analyze the web content for the right keywords, back-links etc and optimizes the content. Some common SEO tools are Bing Webmaster Tools, Data Studio, Enhanced Google Analytics Annotations, Mozcast etc. Now let’s see what are the SEO tools for Laravel. The most popular SEO plug-in for Laravel 5.8+ and Lumen is artesaos/seotools which is available on github. Install the package using composer.composer require artesaos/seotools

You need to update the application configuration in config/app.php file to register the package so that it can be loaded by Laravel. Add the below lines of code to provider section.

<?php

 

return [

// ...

    'providers' => [

        Artesaos\SEOTools\Providers\SEOToolsServiceProvider::class,

        // ...

    ],

    // ...

];

Now to use the SEO Meta facades set up a short-version aliases like  the below given lines to your config/app.php file.

<?php

 

return [

    // ...

    'aliases' => [

        'SEOMeta'   => Artesaos\SEOTools\Facades\SEOMeta::class,

        'OpenGraph' => Artesaos\SEOTools\Facades\OpenGraph::class,

        'Twitter'   => Artesaos\SEOTools\Facades\TwitterCard::class,

        'JsonLd'   => Artesaos\SEOTools\Facades\JsonLd::class,

        // or

        'SEO' => Artesaos\SEOTools\Facades\SEOTools::class,

        // ...

    ],

    // ...

];

Publish the config using command 

php artisan vendor:publish

or

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

Now its time to use the SEO tool in your application. Create a route and a controller.

Route::get('article','ArticleController@article')->name('article');

php artisan make:controller ArticleController

Add some code in your controller ArticleController.php

<?php

 

namespace App\Http\Controllers;

 

use Illuminate\Http\Request;

use SEOMeta;

use OpenGraph;

use Twitter;

## or

use SEO;

class ArticleController extends Controller

{

    public function article()

    {

               

        $title = "This is a blog title";

        $description ="This is a description of my blog post";

        $body        = "This is main body of my blog post";

 

        SEO::setTitle($title);

        SEO::setDescription('This is my page description');

     

        return view('article',compact('title','description','body'));

    }

}

Lastly create the view blade and add HTML code to view title, description and body.

<!DOCTYPE html>

<html>

<head>

                {!! SEO::generate() !!}

 

</head>

<body>

                <h1>{{$title}}</h1> <br>

                <h2>{{$description}}</h2> <br>

                <p>{{$body}}</p>

</body>

</html>

You can see the SEO metatags on the view source page.