10-Apr-2023
.
Admin
Hi Guys
In this example,I will explain you how to use SEOTools in laravel 7. we will show example seo tools in laravel 7. i will generate seotools useing artesaos api. you can easy use SEOTools in laravel 7. i will show step by step laravel 7 artesaos seotools tutorial.
Here, I will give you full example for simply artesaos seotools using laravel 7 as bellow.
Step 1: Install Dependency
The first step is using composer to install the package and automatically update your composer.json file, you can do this by running:
composer require artesaos/seotools
Step 2:Provider
In this setp,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:
Path
config/app.php
<?php
return [
// ...
'providers' => [
Artesaos\SEOTools\Providers\SEOToolsServiceProvider::class,
// ...
],
// ...
];
Step 3:Facades
You may get 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
You can setup a short-version aliases for these facades 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 4: Configuration
In your terminal type
php artisan vendor:publish --provider="Artesaos\SEOTools\Providers\SEOToolsServiceProvider"
In seotools.php configuration file you can determine the properties of the default values and some behaviors.
config/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.
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.
json-ld
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.
Step 4: Create Controller and Usage
In this step, open your terminal and run the following command to create SEO controller file for generate seo tag:
php artisan make:controller SEOToolsController
This command will create a controller
named SEOToolsController.php file.
Next, Navigate to app/http/controllers/ folder and open
SEOToolsController.php. Then add the following SEOTools methods into your SEOToolsController.php file:
<?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
in this step,the parameter true to get minified code and reduce filesize. create seoTools balde file following path /resources/views/seoTools.blade.php
<!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>
Out Put
It will help you...
#Laravel 7
#Laravel
#Laravel 6