1. Go to this page and download the library: Download esign/laravel-seo 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/ */
esign / laravel-seo example snippets
return [
/**
* The class that will be used when you call the Seo facade or the seo helper method.
* The configured class must extend the `Esign\Seo\Seo` class.
*/
'seo' => \Esign\Seo\Seo::class,
/**
* Tags are used to represent their own set of specific attributes.
* The configured tags must extend their corresponding base class.
*/
'tags' => [
'meta' => \Esign\Seo\Tags\Meta::class,
'open_graph' => \Esign\Seo\Tags\OpenGraph::class,
'twitter_card' => \Esign\Seo\Tags\TwitterCard::class,
'json_ld' => \Esign\Seo\Tags\JsonLd::class,
],
];
use Esign\Seo\Facades\Seo;
class PostController extends Controller
{
public function show(Post $post)
{
Seo::setTitle($post->title)->setDescription($post->description);
return view('posts.show', compact('post'));
}
}
use Esign\Seo\Facades\Seo;
use Esign\Seo\Facades\Tags\Meta;
use Esign\Seo\Facades\Tags\OpenGraph;
use Esign\Seo\Facades\Tags\TwitterCard;
Seo::meta()->setTitle('My Meta Title');
Seo::og()->setTitle('My Open Graph Title');
Seo::twitter()->setTitle('My Twitter Title');
Meta::setTitle('My Meta Title');
OpenGraph::setTitle('My Open Graph Title');
TwitterCard::setTitle('My Twitter Card Title');
use Esign\Seo\Facades\Seo;
use Esign\Seo\Tags\Meta;
use Esign\Seo\Tags\OpenGraph;
use Esign\Seo\Tags\TwitterCard;
Seo::meta(fn (Meta $meta) => $meta->setTitle('My Meta Title'))
->og(fn (OpenGraph $openGraph) => $openGraph->setTitle('My Open Graph Title'))
->twitter(fn (TwitterCard $twitterCard) => $twitterCard->setTitle('My Twitter Card Title'));
use Esign\Seo\Tags\Meta as EsignMeta;
class Meta extends EsignMeta
{
public function setDescriptionAttribute(?string $value): string
{
return (string) Str::limit($value, 160, '');
}
}
public function setTitleAttribute(?string $title): ?string
{
return sprintf('%s | %s', $title, config('app.name'));
}
Seo::setTitle('My Normal Seo Title'); // <title>My Normal Seo Title | Esign</title>
Seo::setRaw('title', 'My Raw Seo Title'); // <title>My Raw Seo Title</title>
use Esign\Seo\Concerns\HasSeoDefaults;
use Esign\Seo\Contracts\SeoContract;
class Post extends Model implements SeoContract
{
use HasSeoDefaults;
public function getSeoUrl(): ?string
{
return route('posts.show', ['slug' => $this->slug]);
}
}
use Esign\Seo\Facades\Seo;
class PostController extends Controller
{
public function show(Post $post)
{
Seo::set($post);
return view('posts.show', compact('post'));
}
}