- How do I generate JSON-LD for a product page in Laravel using spatie/schema-org?
- Use the fluent builder to chain properties like `Schema::product()->name('Laptop')->brand('Tech Corp')`, then embed the output in your Blade view with `{{ $schema->toScript() }}`. This auto-generates valid `<script type="application/ld+json">` for Google’s structured data.
- Does spatie/schema-org support Laravel’s Eloquent models for dynamic schema generation?
- Yes. Map model attributes to Schema.org properties by creating a service or binding a schema builder to your model. For example, `Schema::product()->name($product->title)->price($product->price)` dynamically pulls data from Eloquent records.
- Can I use this package with Laravel APIs to return structured data in responses?
- Absolutely. Serialize schemas in API responses with `$response->json($schema->toArray())` or return the JSON-LD script directly. This ensures APIs provide machine-readable data for search engines and tools like Google’s Rich Results.
- How does spatie/schema-org handle Schema.org updates (e.g., new types or properties)?
- The package auto-generates classes from Schema.org’s official JSON-LD file, so new types/properties are added in minor updates. Always check the [changelog](https://github.com/spatie/schema-org/releases) and test with Google’s [Structured Data Testing Tool](https://search.google.com/test/rich-results) after major updates.
- Is there a performance impact when generating complex schemas (e.g., 50+ nested entities)?
- For large graphs, benchmark your use case. The package is optimized for typical SEO needs, but consider caching generated JSON-LD (e.g., via Laravel’s cache system) or lazy-loading relationships. Avoid over-fetching data in dynamic contexts.
- How do I validate generated JSON-LD before deploying to production?
- Use Google’s [Rich Results Test](https://search.google.com/test/rich-results) or integrate the [Schema.org Validator](https://validator.schema.org/) in your tests. For automated checks, add a unit test comparing your schema output to a known-valid JSON-LD snippet.
- Can I extend spatie/schema-org to support custom Schema.org properties not in the core vocabulary?
- Yes. Use `setProperty('customField', 'value')` or `addProperty()` for non-standard fields. Document these in your codebase and validate against Schema.org’s [extension guidelines](https://schema.org/docs/extension.html) to avoid SEO risks.
- What Laravel versions does spatie/schema-org support, and how do I install it?
- The package supports Laravel 8+ (PHP 8.0+). Install via Composer: `composer require spatie/schema-org`. Register the service provider in `config/app.php` if using Laravel <9.0, though it’s autoloaded in newer versions.
- How do I handle multilingual Schema.org properties (e.g., `name` in multiple languages)?
- Use the `addLanguage()` method or chain properties with language tags: `Schema::localBusiness()->name('Name', 'en')->name('Nom', 'fr')`. This generates localized JSON-LD compliant with Schema.org’s multilingual standards.
- Are there alternatives to spatie/schema-org for Laravel, and why should I choose this one?
- Alternatives include manual JSON-LD generation or packages like `digitalbrain/schema.org`, but spatie/schema-org offers a **fluent, type-safe builder** auto-generated from Schema.org’s official standards, ensuring 100% coverage and SEO compliance. Its Laravel-native integration (Blade, Eloquent, APIs) and Graph class for relationships set it apart.