Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Seokit Laravel Package

larament/seokit

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require larament/seokit
    php artisan seokit:install
    php artisan migrate
    
    • Publishes config (config/seokit.php), migrations, and Blade directives.
  2. 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'));
    }
    
  3. Render in Blade: Add @seoKit directive to your layout’s <head>:

    <!DOCTYPE html>
    <html>
    <head>
        @seoKit
        <!-- Other meta tags -->
    </head>
    </html>
    
  4. Verify Output: View page source to confirm generated <title>, <meta>, Open Graph, and Twitter tags.

Key Starting Points

  • Facade API: SeoKit::title(), SeoKit::description(), etc. (see wiki/API).
  • Model Traits: HasSeo and HasSeoData for database-backed SEO (see wiki/Database-Backed-SEO).
  • Configuration: config/seokit.php (e.g., site_name, default_description).

Implementation Patterns

1. Controller-Driven SEO

Workflow:

  • Use SeoKit facade in controllers to set dynamic metadata.
  • Chain methods for clarity:
    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:

  • Route Model Binding: Combine with 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'));
    }
    
  • Middleware: Centralize SEO for guest routes:
    SeoKit::title(config('app.name'))
          ->description(config('seokit.default_description'));
    

2. Model-Backed SEO

Workflow:

  1. Add traits to your model:
    use Larament\SeoKit\Traits\HasSeo;
    use Larament\SeoKit\Traits\HasSeoData;
    
    class Post extends Model {
        use HasSeo, HasSeoData;
    }
    
  2. Define fallback SEO in the model:
    protected function fallbackSeoData(): array {
        return [
            'title' => 'Untitled Post',
            'description' => 'No description available.',
        ];
    }
    
  3. Access SEO via relationships:
    $post->seoData; // Returns SeoData model or null
    

Integration Tips:

  • Polymorphic Relationships: Use seoable() for shared SEO tables:
    public function seoData() {
        return $this->morphOne(SeoData::class, 'seoable');
    }
    
  • Admin Panels: Integrate with Nova or Filament for SEO CRUD:
    // Filament Resource
    public static function form(Form $form): Form {
        return $form->schema([
            SeoKit::make('seo_data')->relationship(),
        ]);
    }
    

3. Blade Directives

Patterns:

  • Dynamic SEO: Use @seoKit in layouts or partials.
  • Conditional Rendering: Override SEO for specific pages:
    @if(request()->is('home'))
        @seoKit(['title' => 'Homepage'])
    @else
        @seoKit
    @endif
    
  • JSON-LD: Render structured data directly:
    @seoKit(['jsonLd' => view('partials.schema.org/json-ld')])
    

4. Caching and Performance

Patterns:

  • Automatic Caching: SeoKit caches SEO data by default (TTL configurable in config/seokit.php).
  • Manual Cache Control:
    SeoKit::cacheFor(3600); // Cache for 1 hour
    SeoKit::forget(); // Clear cache
    
  • View Composers: Pre-load SEO for static pages:
    public function compose(View $view) {
        $view->withSeo(SeoKit::getCached());
    }
    

5. Inertia.js Integration

Workflow:

  • Enable Inertia.js support in config/seokit.php:
    'inertia' => true,
    
  • SEO is automatically synced with Inertia page titles:
    // Inertia Controller
    public function show(Post $post) {
        SeoKit::title($post->title);
        return Inertia::render('Posts/Show', ['post' => $post]);
    }
    

Gotchas and Tips

Pitfalls

  1. Missing @seoKit Directive:

    • Symptom: No meta tags rendered despite setting SEO in the controller.
    • Fix: Ensure @seoKit is placed in the <head> of your layout.
  2. Fallback SEO Not Triggering:

    • Cause: HasSeo::prepareSeoTags() requires either a seoData record or a fallbackSeoData() method.
    • Fix: Verify the model has:
      use HasSeo;
      protected function fallbackSeoData(): array { ... }
      
  3. Canonical URL Conflicts:

    • Cause: Multiple canonical() calls override each other.
    • Fix: Set canonical once (e.g., in a middleware or base controller).
  4. JSON-LD Validation Errors:

    • Cause: Invalid schema.org syntax.
    • Fix: Use Google’s Rich Results Test and validate with:
      SeoKit::jsonLd($this->validateJsonLd($structuredData));
      
  5. Caching Issues:

    • Cause: Stale SEO data due to aggressive caching.
    • Fix: Use SeoKit::forget() in critical paths (e.g., after SEO updates):
      SeoKit::forget(); // Clear cache on SEO model updates
      

Debugging Tips

  1. Inspect Raw SEO Data:
    dd(SeoKit::getMetaTags()->toArray());
    
  2. Check Cached Data:
    SeoKit::getCached(); // Returns cached SEO array
    
  3. Validate Open Graph/Twitter:
  4. Log SEO Changes:
    SeoKit::logChanges(); // Enable in config/seokit.php
    

Configuration Quirks

  1. site_name Default:

    • Falls back to config('app.name') if not set in config/seokit.php.
  2. Locale Support:

    • Use SeoKit::setLocale('es') for multi-language SEO:
      SeoKit::setLocale(request()->locale)
            ->title(__('posts.title'));
      
  3. Default Description:

    • Configure in config/seokit.php:
      'default_description' => 'Welcome to our site!',
      

Extension Points

  1. Custom Meta Tags:

    • Extend MetaTags class or use the extraTags method:
      SeoKit::extraTags([
          '<meta name="author" content="John Doe">',
      ]);
      
  2. Structured Data Helpers:

    • Create a helper for common JSON-LD:
      function articleJsonLd(Post $post) {
          return [
              '@context' => 'https://schema.org',
              '@type' => 'BlogPosting',
              'headline' => $post->title,
              'datePublished' => $post->published_at->toISOString(),
          ];
      }
      
  3. Event Listeners:

    • Trigger SEO updates on model events:
      Post::updated(function (Post $post) {
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky