- How do I add SEO metadata to a Laravel page without cluttering my controllers?
- Use the `@seoKit` Blade directive to define metadata directly in your views. For example, `@seoKit(['title' => 'Page Title', 'description' => 'Meta description'])` injects the tags without controller logic. This keeps your controllers clean while maintaining SEO control.
- Does SeoKit support JSON-LD structured data for rich snippets?
- Yes, SeoKit prioritizes JSON-LD structured data out of the box. You can define it via the facade (`SeoKit::jsonLd(['@type' => 'Article'])`) or model traits, ensuring your content appears in rich snippets on Google and other search engines.
- Can I use SeoKit with Laravel 10 or older versions?
- No, SeoKit requires Laravel 11+ and PHP 8.3+. If you’re on an older version, plan a minor upgrade to leverage its features. The package is designed for modern Laravel, so compatibility with older versions isn’t supported.
- How does SeoKit handle caching to avoid N+1 query issues?
- SeoKit integrates with Laravel’s cache system to store meta tags and SEO data. Enable caching via `SeoKit::cache(true)` or configure TTL in the config. For high-traffic pages, use Redis or database caching to minimize redundant queries.
- Is SeoKit compatible with Inertia.js for SPAs?
- Yes, SeoKit has native Inertia.js support (v1.1.0+). Use the `@seoKit` directive in your layouts or share SEO data globally via `Inertia::share` to ensure server-rendered SEO tags work seamlessly with client-side navigation.
- How do I store SEO metadata in the database for dynamic content?
- Publish the migrations with `php artisan seokit:install` and use the `HasSeo` trait on your models. This creates a `seo_data` table with polymorphic relationships, allowing you to store SEO metadata separately from your domain models.
- What’s the best way to test SEO tags in my Laravel app?
- Use Laravel’s HTTP tests to assert meta tags. For example, `get('/post')->assertSeeInHeadline('Page Title')` or `assertSeeInHead('description', 'Meta description')`. SeoKit’s facade and Blade directives make testing straightforward.
- Can SeoKit replace existing SEO middleware or packages like Spatie’s Meta package?
- SeoKit is a complete alternative to Spatie’s Meta package, offering meta tags, Open Graph, Twitter Cards, and JSON-LD in one package. It’s designed for modern Laravel and includes caching, Inertia.js support, and polymorphic SEO—making it a drop-in replacement for many use cases.
- How do I handle fallback SEO data if primary metadata is missing?
- Use the `fallbackSeoData()` method to define defaults. For example, `SeoKit::fallbackSeoData(['title' => 'Default Title'])` ensures metadata is never empty. This is useful for dynamic content where some fields might be null.
- Does SeoKit support multi-language SEO for localized apps?
- Yes, SeoKit supports localization via fallback logic and polymorphic relationships. Store language-specific SEO data in the `seo_data` table and use the `HasSeo` trait to dynamically fetch metadata based on the current locale.