Hello Devs,
In this tutorial, we will learn Laravel 7 Artesaos SEOTools Tutorial
In this section, we will generate seotools useing artesaos api. you can easy use SEOTools in laravel 7.
Follow this step by step guide below.
Step 1: Install Dependency
composer require artesaos/seotools
Step 2:Provider
update your config/app.php file adding the following code at the end of your 'providers'
Path
config/app.php
<?php
return [
// ...
'providers' => [
Artesaos\SEOTools\Providers\SEOToolsServiceProvider::class,
// ...
],
// ...
];
Step 3:Facades
access to the SEO tool services using following facades:
- Artesaos\SEOTools\Facades\SEOMeta
- Artesaos\SEOTools\Facades\OpenGraph
- Artesaos\SEOTools\Facades\TwitterCard
- Artesaos\SEOTools\Facades\JsonLd
- Artesaos\SEOTools\Facades\JsonLdMulti
- Artesaos\SEOTools\Facades\SEOTools
<?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 4: Configuration
php artisan vendor:publish --provider="Artesaos\SEOTools\Providers\SEOToolsServiceProvider"
config/seotools.php
Step 4: Create Controller and Usage
php artisan make:controller SEOToolsController
add the following SEOTools methods into your SEOToolsController.php file:
SEOToolsController.php.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
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;
class SEOToolsController extends Controller
{
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');
TwitterCard::setTitle('Homepage');
TwitterCard::setSite('@LuizVinicius73');
JsonLd::setTitle('Homepage');
JsonLd::setDescription('This is my page description');
JsonLd::addImage('https://codecasts.com.br/img/logo.jpg');
// OR
SEOTools::setTitle('Home');
SEOTools::setDescription('This is my page description');
SEOTools::opengraph()->setUrl('http://current.url.com');
SEOTools::setCanonical('https://codecasts.com.br/lesson');
SEOTools::opengraph()->addProperty('type', 'articles');
SEOTools::twitter()->setSite('@LuizVinicius73');
SEOTools::jsonLd()->addImage('https://codecasts.com.br/img/logo.jpg');
return view('seoTools');
}
}
Step 5: Create View
<!DOCTYPE html>
<html>
<head>
<title>Laravel 7 Artesaos SEOTools Tutorial</title>
{!! SEOMeta::generate() !!}
{!! OpenGraph::generate() !!}
{!! Twitter::generate() !!}
{!! JsonLd::generate() !!}
{!! JsonLdMulti::generate() !!}
{!! SEO::generate() !!}
{!! SEO::generate(true) !!}
{!! app('seotools')->generate() !!}
</head>
<body>
<div class="container">
<div class="text-center">
<h4>Laravel 7 Artesaos SEOTools Tutorial</h4>
</div>
</div>
</body>
</html>
May this example help you.