Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Schema Org Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Schema.org Alignment: The package provides a fluent, type-safe builder for all Schema.org types (e.g., LocalBusiness, Product, Article), ensuring compliance with structured data standards. This aligns well with Laravel applications needing SEO optimization, rich snippets, or knowledge graph integration.
  • JSON-LD Generation: Automatically generates valid ld+json output, reducing manual JSON handling and validation risks.
  • Graph & Multi-Type Entities: Supports complex relationships (e.g., nested OrganizationPersonProduct) and multi-typed entities (e.g., HotelRoom + Product), which is critical for e-commerce, local businesses, or media sites.
  • Laravel Synergy: Works seamlessly with Laravel’s Blade templating (via toScript()) and API responses (via toArray()/json_encode()).

Integration Feasibility

  • Low Friction: Requires zero Laravel-specific dependencies (pure PHP), making integration trivial via Composer.
  • Blade Integration: Can be embedded in views via @php or custom Blade directives (e.g., @schemaOrg).
  • API/JSON Responses: Directly serializable to JSON for API endpoints (e.g., GraphQL, REST).
  • Caching: Schema objects can be cached (e.g., via Laravel’s cache) if generated dynamically (e.g., for product pages).

Technical Risk

  • Schema.org Versioning: The package auto-updates with Schema.org releases (currently v29.3). Risk: Breaking changes if Schema.org modifies core types/properties. Mitigation: Test with Google’s Structured Data Testing Tool and monitor changelog.
  • Performance: Generating large graphs (e.g., 100+ products) may impact memory. Mitigation: Use Laravel’s queue system or fragment caching for heavy pages.
  • HTML Injection: 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.
  • Missing Types: Physician (health extension) and Float (reserved keyword) are unsupported. Mitigation: Use setProperty for edge cases.

Key Questions

  1. Use Case Scope:
    • Will this be used for global site markup (e.g., Organization in <head>) or dynamic content (e.g., product pages)?
    • Are multi-typed entities (e.g., Product + Offer) needed, or will simple types suffice?
  2. Data Source:
    • Will schemas be hardcoded, database-driven (e.g., Eloquent models), or API-fetched (e.g., CMS content)?
  3. Validation:
    • Should invalid Schema.org properties be rejected at runtime (e.g., via a validator) or silently ignored?
  4. Performance:
    • For high-traffic sites, should schemas be pre-generated (e.g., during deployment) or built on-demand?
  5. Testing:
    • Will Google’s Rich Results Test or Schema.org Validator be integrated into CI/CD?

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Blade: Use toScript() in layouts or partials (e.g., @include('schemas.org', ['business' => $business])).
    • APIs: Return toArray() in JSON responses (e.g., return response()->json($product->schema())).
    • Service Providers: Register a macro (e.g., Str::schemaOrg()) or helper (e.g., schema_org()) for global access.
    • Eloquent: Extend models with a schema() method (e.g., Product::schema()Schema::product()).
  • Frontend:
    • Works with Next.js/Nuxt via API routes or static JSON-LD files.
    • Compatible with Alpine.js for dynamic updates (e.g., real-time search results).

Migration Path

  1. Pilot Phase:
    • Start with static schemas (e.g., Organization in <head>, BreadcrumbList for navigation).
    • Use Blade directives for templating:
      // app/Providers/AppServiceProvider.php
      Blade::directive('schemaOrg', function ($expression) {
          return "<?php echo {$expression}->toScript(); ?>";
      });
      
      @schemaOrg(\Spatie\SchemaOrg\Schema::localBusiness()->name('Acme Corp'))
      
  2. Dynamic Integration:
    • Add 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));
          }
      }
      
    • Use observers or model events to auto-generate schemas on save.
  3. Advanced Use Cases:
    • Implement a Graph service to manage complex relationships (e.g., OrganizationEmployeeProject).
    • Use caching for frequently accessed schemas (e.g., cache()->remember('business-schema', now()->addHour(), fn() => Schema::localBusiness()->...)).

Compatibility

  • PHP 8.2+: Required for v4.x. Ensure Laravel version supports this (Laravel 10+).
  • Schema.org Updates: Monitor Schema.org releases and test upgrades.
  • Third-Party Tools:
    • Google Tag Manager: Can inject ld+json via custom HTML tags.
    • SEO Packages: May conflict if they also generate Schema.org markup (e.g., spatie/laravel-seo). Solution: Consolidate to one package.

Sequencing

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

Operational Impact

Maintenance

  • Updates:
    • Minor: Schema.org updates (e.g., v29.3 → v29.4) are backward-compatible and require no code changes.
    • Major: Breaking changes (e.g., PHP 8.2 drop) require dependency updates and testing.
    • Strategy: Pin to a specific Schema.org version (e.g., spatie/schema-org:^4.0) to avoid surprises.
  • Deprecations:
    • Monitor identifier@id migration (already handled in v2.6.0+).
    • Watch for removed types (e.g., Physician may return if health extensions are added).

Support

  • Debugging:
    • Use getProperties() to inspect generated schemas.
    • Validate JSON-LD with Google’s tool.
  • Common Issues:
    • Missing Properties: Ensure all required fields (e.g., name for LocalBusiness) are set.
    • Nested Objects: Verify toArray() output matches expectations (e.g., contactPoint structure).
    • Performance: Profile with memory_get_usage() for large graphs.
  • Documentation:
    • Internal Wiki: Document schema usage per feature (e.g., "Product Page Schema").
    • Code Comments: Annotate dynamic schemas (e.g., // Generates JSON-LD for SEO).

Scaling

  • Performance:
    • Large Graphs: Use Laravel queues to generate schemas asynchronously (e.g., for 1000+ products).
    • Caching: Cache schemas for static content (e.g., cache()->forever('business-schema', $schema)).
    • Lazy Loading: Defer schema generation until needed (e.g., only on GET requests).
  • Database:
    • Store serialized schemas in a structured_data column if frequently updated.
    • Example:
      $product->structured_data = json_encode($product->schema());
      $product->save();
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai