Laravel 7 Artesaos SEOTools Tutorial
Teams applying “Laravel 7 Artesaos SEOTools Tutorial” in a production project can use employee termination to record implementation, review and debugging time, then compare that effort with tests and shipped functionality instead of treating activity as performance by itself.
Before copying the example into a live application, confirm version-specific behaviour with the official Laravel website and test it against the project’s actual database and runtime.
Aug 13, 2020
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.
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.
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...
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial