Laravel 8 Artesaos SEOTools Tutorial

Websolutionstuff | Jun-07-2021 | Categories : Laravel

Hello Devs,

In this tutorial we will learn how to use SEOTools in laravel 8. we will give you example of seo tools in laravel 8. I will use Artesaos SEOTools for website seo. I will show you step by step for Laravel 8 Artesaos SEOTools tutorial.

Artesaos SEOTools provides features like below list

 

Step 1 : Install Artesaos SEOTools Package

First step is install package in your project using command line. so run below command on your terminal. composer to install the package and automatically update your composer.json file.

composer require artesaos/seotools

 

 

Step 2 : Update Provider and Aliases

In this step just update your config/app.php file adding the following code at the end of your 'providers' and 'aliases' section.

File Path : config/app.php

<?php

return [
    'providers' => [
        Artesaos\SEOTools\Providers\SEOToolsServiceProvider::class,
        // ...
    ],    
];

 

You can setup aliases in your config/app.php file. For example:

<?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,
        'JsonLdMulti'   => Artesaos\SEOTools\Facades\JsonLdMulti::class,
        // or
        'SEO' => Artesaos\SEOTools\Facades\SEOTools::class,
    ],
];

 

Step 3 : Use Facades

You may get access to the SEO tool services using following facades: so as your requirements you can use or include facades in your controller.

use Artesaos\SEOTools\Facades\SEOMeta;
use Artesaos\SEOTools\Facades\OpenGraph;
use Artesaos\SEOTools\Facades\TwitterCard;
use Artesaos\SEOTools\Facades\JsonLd;
use Artesaos\SEOTools\Facades\JsonLdMulti;
use Artesaos\SEOTools\Facades\SEOTools;

 

Step 4 : Vendor Publish

In your terminal type below command publish Artesaos\SEOTools package.

php artisan vendor:publish

or

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

after publishing this package you can determine config/seotools.php in your project.

 

 

Step 5 :  Usage in Controller

 

<?php

namespace App\Http\Controllers;

use Artesaos\SEOTools\Facades\SEOMeta;
use Artesaos\SEOTools\Facades\OpenGraph;
use Artesaos\SEOTools\Facades\TwitterCard;
use Artesaos\SEOTools\Facades\JsonLd;
// OR with multi
use Artesaos\SEOTools\Facades\JsonLdMulti;

// OR use only single facades
use Artesaos\SEOTools\Facades\SEOTools;

class SEOController extends Controller
{
    public function index()
    {
        SEOMeta::setTitle('Websolutionstuff | Home');
        SEOMeta::setDescription('This is my page description of websolutionstuff');
        SEOMeta::setCanonical('https://websolutionstuff.com');

        OpenGraph::setDescription('This is my page description of websolutionstuff');
        OpenGraph::setTitle('Websolutionstuff | Home');
        OpenGraph::setUrl('https://websolutionstuff.com');
        OpenGraph::addProperty('type', 'articles');

        TwitterCard::setTitle('Websolutionstuff | Homepage');
        TwitterCard::setSite('@websolutionstuff');

        JsonLd::setTitle('Websolutionstuff | Homepage');
        JsonLd::setDescription('This is my page description of websolutionstuff');
        JsonLd::addImage('https://websolutionstuff.com/frontTheme/assets/images/logo.png');

        // OR use single only SEOTools

        SEOTools::setTitle('Websolutionstuff | Home');
        SEOTools::setDescription('This is my page description of websolutionstuff');
        SEOTools::opengraph()->setUrl('https://websolutionstuff.com/');
        SEOTools::setCanonical('https://websolutionstuff.com');
        SEOTools::opengraph()->addProperty('type', 'articles');
        SEOTools::twitter()->setSite('@websolutionstuff');
        SEOTools::jsonLd()->addImage('https://websolutionstuff.com/frontTheme/assets/images/logo.png');

        return view('posts');
    }   
}

 

Step 6: Use in View file

 

<html>
<head>
    {!! SEOMeta::generate() !!}
    {!! OpenGraph::generate() !!}
    {!! Twitter::generate() !!}
    {!! JsonLd::generate() !!}
    // OR with multi
    {!! JsonLdMulti::generate() !!}

    <!-- OR -->
    {!! SEO::generate() !!}

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

</head>
<body>
 <h3>Laravel 8 SEO Tutorial</h3>
</body>
</html>

 

Recommended Post
Featured Post
How To Add jQuery Datatable Column Filter Dropdown On Top
How To Add jQuery Datatable Co...

In this article, we will see how to add a jquery datatable column filter dropdown on top. Here, we will learn how t...

Read More

Jan-19-2023

Laravel whereIn and whereNotIn Query Example
Laravel whereIn and whereNotIn...

In this article, we will see the laravel whereIn and whereNotIn query examples. laravel query builder provides many diff...

Read More

Jan-16-2021

What Is New In Laravel 9 - Features Of Laravel 9
What Is New In Laravel 9 - Fea...

In this article, we will see what is new in laravel 9 and the features of laravel 9. Laravel 9 is recently released...

Read More

Feb-13-2022

Autotab To Next Input Field JQuery
Autotab To Next Input Field JQ...

In this article, we will see how to focus on the next input when the max length is reached. Sometimes we have...

Read More

Aug-19-2020