spatie/schema-org
Fluent PHP builder for Schema.org: generate any type and property from the full core vocabulary and output valid JSON-LD (ld+json) script tags. Generated from the official Schema.org JSON-LD, with documented classes and methods.
Response::json() with embedded Schema.org data).$product->name('Laptop')->price(999)->review('5★')) reduce boilerplate.ld+json for direct inclusion in <script type="application/ld+json"> or API responses.BreadcrumbList with 100 items) could impact response times. Mitigation:
required fields). Risk: Invalid markup may slip through. Mitigation:
Product vs. VideoObject)?seo packages (e.g., spatie/laravel-seo) or standalone?@schema directives or view composers.
// app/ViewComposers/SchemaComposer.php
public function compose($view) {
$view->with('schema', Schema::type('Product')->name('Widget')->price(19.99));
}
<script type="application/ld+json">{{ $schema->toScript() }}</script>
ProductResource).
public function toArray($request) {
return [
'data' => $this->product->toArray(),
'schema' => Schema::type('Product')->name($this->product->name)->price($this->product->price),
];
}
app/Schema/Types/Product.php).Product, Article) in a single feature.GET /products/{id} returns both product data and embedded Product type.| Step | Task | Owner | Dependencies |
|---|---|---|---|
| 1. Setup | Install package (composer require spatie/schema-org). |
Backend | None |
| 2. Pilot | Implement 1–2 Schema types in a feature branch. | Backend | Step 1 |
| 3. Template | Replace manual JSON-LD in Blade with fluent builder. | Frontend/Backend | Step 2 |
| 4. API | Extend API resources to include Schema.org metadata. | Backend | Step 3 |
| 5. Validation | Add tests for JSON-LD output and integrate Google’s validator. | QA/Backend | Step 4 |
| 6. Monitor | Track Schema.org updates and package releases. | PM/Backend | Ongoing |
app/Schema/Types/CustomType.php).namespace App\Schema\Types;
use Spatie\SchemaOrg\Schema;
class CustomType extends Schema {
public function __construct() {
parent::__construct('CustomType');
}
public function customProperty(string $value): self { ... }
}
Schema::debug() to inspect generated JSON-LD.Product type for /products/* routes").// Laravel Cache
$schema = Cache::remember("schema_product_{$product->id}", now()->addHours(1), fn() =>
Schema::type('Product')->name($product->name)->price($product->price)
);
BreadcrumbList), consider lazy-loading or pagination.| Risk | Impact | Mitigation Strategy |
|---|---|---|
| Schema.org breaking changes | Invalid JSON-LD in production | Quarterly audit of Schema.org updates |
| Missing required fields | Google ignores rich snippets | Runtime validation (e.g., Laravel Form Requests) |
| Performance bottlenecks | Slow API/rendering | Benchmark with expected payload sizes |
| Package abandonment | No future updates | Fork if Spatie stops maintaining (MIT license) |
| SEO misconfiguration | Wrong Schema type used | Document type-to-route mappings |
How can I help you explore Laravel packages today?