- How do I quickly add SEO to a Laravel app without writing custom meta tags?
- Install the package via Composer, publish the migrations and config, then use `{!! seo()->for($model) !!}` in your Blade layouts. It auto-generates title, OpenGraph, Twitter Cards, and structured data from your model’s associated SEO record or dynamic methods.
- Does this package support Laravel 10+ and work with Eloquent models?
- Yes, it’s fully compatible with Laravel 9/10/11 and designed for Eloquent. Use the `HasSEO` trait on models to link them to SEO data, or dynamically fetch SEO via `getDynamicSEOData()` without saving to the database.
- Can I customize OpenGraph or Twitter Cards for specific pages?
- Absolutely. Override the `getDynamicSEOData()` method in your model to return a `SEOData` object with custom properties like `image`, `description`, or `twitter_card`. The package merges these with your stored SEO data automatically.
- What if I don’t want to store SEO in the database? Can I use dynamic data only?
- Yes. Skip the migration and manually instantiate `SEOData` in your controller or view. Pass it to `seo()->for($data)` to render tags without database dependencies. Ideal for lightweight or API-driven apps.
- How do I add custom JSON-LD structured data (e.g., Product schema)?
- Configure the `structured_data` key in `config/seo.php` with your schema type (e.g., `Product`). The package will generate valid JSON-LD. For dynamic schemas, extend the `SEOData` class or use the `structured_data` property in `getDynamicSEOData()`.
- Will this conflict with spatie/laravel-head or other meta-tag packages?
- Potential conflicts exist if both packages manage the same tags. Disable one or configure them to share the same Blade directive (e.g., `{!! seo()->render() !!}`). Test in staging to ensure no tag duplication or overrides.
- How do I handle multi-language SEO (hreflang tags) with this package?
- Use the `alternates` property in `SEOData` or the `alternates` config array to define language-specific URLs. The package auto-generates hreflang tags. For dynamic locales, override `getDynamicSEOData()` to return locale-aware data.
- Can I cache SEO data to improve performance?
- Yes. Cache the `SEOData` object or the associated model’s SEO record using Laravel’s cache. Invalidate the cache when SEO data updates (e.g., via model observers or events). For dynamic data, cache the result of `getDynamicSEOData()`.
- Does this work with Inertia.js or SPAs? How do I sync SEO with client-side routes?
- The package is SSR-focused, but you can pass SEO data to Inertia via props or share directives. Use middleware to fetch `SEOData` for each route and include it in your Vue/React page metadata. For dynamic routes, call `seo()->for($data)` in your Inertia layout.
- What’s the best way to test SEO tag generation in my Laravel app?
- Use PHPUnit to assert rendered HTML contains expected meta tags. Mock the `SEO` model or `SEOData` object and test `seo()->for($model)->render()`. For structured data, validate JSON-LD output with Google’s Rich Results Test or a JSON schema validator.