1. Go to this page and download the library: Download magutti/seo-tools library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Magutti\SeoTools\Facades\SEOTools as SEO;
class ArticleController extends Controller
{
public function show(Article $article)
{
SEO::setTitle($article->title)
->setDescription($article->excerpt)
->setCanonical(route('articles.show', $article))
->addImages([$article->cover_url]);
return view('articles.show', compact('article'));
}
}
use Magutti\SeoTools\Traits\SEOTools;
class PostController extends Controller
{
use SEOTools;
public function show(Post $post)
{
$this->seo()->setTitle($post->title);
}
}
use Magutti\SeoTools\Facades\JsonLdMulti;
// First block (index 0 is created automatically)
JsonLdMulti::setType('Article')->setTitle('Article Title');
// Add a second block
JsonLdMulti::newJsonLd()
->setType('BreadcrumbList')
->addValue('itemListElement', [/* breadcrumb items */]);
// Switch between blocks
JsonLdMulti::select(0)->setDescription('Updated description');
use Magutti\SeoTools\Contracts\SEOFriendly;
use Magutti\SeoTools\Contracts\MetaTags;
use Magutti\SeoTools\Contracts\OpenGraph;
use Magutti\SeoTools\Contracts\TwitterCards;
use Magutti\SeoTools\Contracts\JsonLd;
class Article extends Model implements SEOFriendly
{
public function loadSEO(MetaTags $meta, OpenGraph $og, TwitterCards $twitter, JsonLd $jsonLd): void
{
$meta->setTitle($this->title)->setDescription($this->excerpt);
$og->setTitle($this->title)->addImage($this->cover_url);
$twitter->setTitle($this->title)->setImage($this->cover_url);
$jsonLd->setType('Article')->setTitle($this->title);
}
}
use Magutti\SeoTools\Traits\SEOTools;
class ArticleController extends Controller
{
use SEOTools;
public function show(Article $article)
{
$this->loadSEO($article);
return view('articles.show', compact('article'));
}
}