spatie/schema-org
Fluent PHP builder for the full Schema.org vocabulary. Create Schema.org types and properties via chainable methods and output valid JSON-LD/ld+json scripts for SEO. Auto-generated from Schema.org standards for complete coverage.
LocalBusiness, Product, Article), ensuring compliance with structured data standards. This aligns well with Laravel applications needing SEO optimization, rich snippets, or knowledge graph integration.ld+json output, reducing manual JSON handling and validation risks.Organization → Person → Product) and multi-typed entities (e.g., HotelRoom + Product), which is critical for e-commerce, local businesses, or media sites.toScript()) and API responses (via toArray()/json_encode()).@php or custom Blade directives (e.g., @schemaOrg).toScript() now escapes <script> tags (fixed in v4.0.2), but custom properties (setProperty) could still introduce XSS if not sanitized. Mitigation: Validate user-provided data.Physician (health extension) and Float (reserved keyword) are unsupported. Mitigation: Use setProperty for edge cases.Organization in <head>) or dynamic content (e.g., product pages)?Product + Offer) needed, or will simple types suffice?toScript() in layouts or partials (e.g., @include('schemas.org', ['business' => $business])).toArray() in JSON responses (e.g., return response()->json($product->schema())).Str::schemaOrg()) or helper (e.g., schema_org()) for global access.schema() method (e.g., Product::schema() → Schema::product()).Organization in <head>, BreadcrumbList for navigation).// app/Providers/AppServiceProvider.php
Blade::directive('schemaOrg', function ($expression) {
return "<?php echo {$expression}->toScript(); ?>";
});
@schemaOrg(\Spatie\SchemaOrg\Schema::localBusiness()->name('Acme Corp'))
schema() methods to Eloquent models:
class Product extends Model {
public function schema() {
return Schema::product()
->name($this->name)
->description($this->description)
->offers(Schema::offer()->price($this->price));
}
}
Organization → Employee → Project).cache()->remember('business-schema', now()->addHour(), fn() => Schema::localBusiness()->...)).ld+json via custom HTML tags.spatie/laravel-seo). Solution: Consolidate to one package.| Phase | Task | Tools/Libraries |
|---|---|---|
| Discovery | Audit existing structured data (e.g., Google Search Console). | Schema.org Validator |
| Setup | Install package, configure Blade/API integration. | Composer, Laravel Blade |
| Pilot | Implement 2–3 critical schemas (e.g., Organization, Product). |
Eloquent macros, Blade directives |
| Validation | Test with Google’s Rich Results Test. | Postman, Browser DevTools |
| Scale | Add dynamic schemas, caching, and performance optimizations. | Laravel Cache, Queue Jobs |
| Monitor | Track schema adoption via Google Search Console. | Analytics, CI/CD tests |
spatie/schema-org:^4.0) to avoid surprises.identifier → @id migration (already handled in v2.6.0+).Physician may return if health extensions are added).getProperties() to inspect generated schemas.name for LocalBusiness) are set.toArray() output matches expectations (e.g., contactPoint structure).memory_get_usage() for large graphs.// Generates JSON-LD for SEO).cache()->forever('business-schema', $schema)).GET requests).structured_data column if frequently updated.$product->structured_data = json_encode($product->schema());
$product->save();
How can I help you explore Laravel packages today?