Installation:
composer require larament/seokit
php artisan seokit:install
php artisan migrate
config/seokit.php), migrations, and Blade directives.First Use Case: In a controller, set SEO metadata for a route:
use Larament\Seokit\Facades\SeoKit;
public function show(Post $post) {
SeoKit::title($post->title)
->description($post->excerpt)
->image($post->featured_image)
->canonical(route('posts.show', $post));
return view('posts.show', compact('post'));
}
Render in Blade:
Add @seoKit directive to your layout’s <head>:
<!DOCTYPE html>
<html>
<head>
@seoKit
<!-- Other meta tags -->
</head>
</html>
Verify Output:
View page source to confirm generated <title>, <meta>, Open Graph, and Twitter tags.
SeoKit::title(), SeoKit::description(), etc. (see wiki/API).HasSeo and HasSeoData for database-backed SEO (see wiki/Database-Backed-SEO).config/seokit.php (e.g., site_name, default_description).Workflow:
SeoKit facade in controllers to set dynamic metadata.SeoKit::title("How to Use SeoKit")
->description("Learn Laravel SEO best practices with SeoKit.")
->image(url('images/seokit-hero.jpg'))
->twitterSite("@larament")
->ogType('article')
->jsonLd([
'@context' => 'https://schema.org',
'@type' => 'BlogPosting',
'headline' => 'SeoKit Guide',
]);
Integration Tips:
HasSeo trait for automatic SEO fetching:
public function show(Post $post) {
SeoKit::useModelFallback($post); // Fallback to model defaults if DB record missing
return view('posts.show', compact('post'));
}
SeoKit::title(config('app.name'))
->description(config('seokit.default_description'));
Workflow:
use Larament\SeoKit\Traits\HasSeo;
use Larament\SeoKit\Traits\HasSeoData;
class Post extends Model {
use HasSeo, HasSeoData;
}
protected function fallbackSeoData(): array {
return [
'title' => 'Untitled Post',
'description' => 'No description available.',
];
}
$post->seoData; // Returns SeoData model or null
Integration Tips:
seoable() for shared SEO tables:
public function seoData() {
return $this->morphOne(SeoData::class, 'seoable');
}
// Filament Resource
public static function form(Form $form): Form {
return $form->schema([
SeoKit::make('seo_data')->relationship(),
]);
}
Patterns:
@seoKit in layouts or partials.@if(request()->is('home'))
@seoKit(['title' => 'Homepage'])
@else
@seoKit
@endif
@seoKit(['jsonLd' => view('partials.schema.org/json-ld')])
Patterns:
config/seokit.php).SeoKit::cacheFor(3600); // Cache for 1 hour
SeoKit::forget(); // Clear cache
public function compose(View $view) {
$view->withSeo(SeoKit::getCached());
}
Workflow:
config/seokit.php:
'inertia' => true,
// Inertia Controller
public function show(Post $post) {
SeoKit::title($post->title);
return Inertia::render('Posts/Show', ['post' => $post]);
}
Missing @seoKit Directive:
@seoKit is placed in the <head> of your layout.Fallback SEO Not Triggering:
HasSeo::prepareSeoTags() requires either a seoData record or a fallbackSeoData() method.use HasSeo;
protected function fallbackSeoData(): array { ... }
Canonical URL Conflicts:
canonical() calls override each other.JSON-LD Validation Errors:
SeoKit::jsonLd($this->validateJsonLd($structuredData));
Caching Issues:
SeoKit::forget() in critical paths (e.g., after SEO updates):
SeoKit::forget(); // Clear cache on SEO model updates
dd(SeoKit::getMetaTags()->toArray());
SeoKit::getCached(); // Returns cached SEO array
SeoKit::logChanges(); // Enable in config/seokit.php
site_name Default:
config('app.name') if not set in config/seokit.php.Locale Support:
SeoKit::setLocale('es') for multi-language SEO:
SeoKit::setLocale(request()->locale)
->title(__('posts.title'));
Default Description:
config/seokit.php:
'default_description' => 'Welcome to our site!',
Custom Meta Tags:
MetaTags class or use the extraTags method:
SeoKit::extraTags([
'<meta name="author" content="John Doe">',
]);
Structured Data Helpers:
function articleJsonLd(Post $post) {
return [
'@context' => 'https://schema.org',
'@type' => 'BlogPosting',
'headline' => $post->title,
'datePublished' => $post->published_at->toISOString(),
];
}
Event Listeners:
Post::updated(function (Post $post) {
How can I help you explore Laravel packages today?