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 Laravel Package

brick/schema

brick/schema is a PHP library to define, validate, and serialize data structures using schemas. Model arrays and objects with clear rules, enforce types and constraints, and convert to/from common formats for safer data exchange and persistence.

View on GitHub
Deep Wiki
Context7

Schema.org library for PHP

Frequently asked questions about Schema
How do I integrate brick/schema into a Laravel project for dynamic product schema generation?
Use Laravel’s service container to bind the SchemaGenerator class, then inject it into controllers or Blade views. For Eloquent models, define accessors to map database fields to schema properties (e.g., `getSchemaProduct()`). Cache generated schemas for static pages to avoid redundant processing.
Does brick/schema support custom Schema.org extensions beyond the standard types?
Yes, the library supports composition, allowing you to extend base Schema.org types (e.g., `Product`) with custom properties or nested types. Document your extensions clearly, as Schema.org validators may flag unknown properties unless properly namespaced.
Can I use brick/schema to generate JSON-LD for API responses in Laravel?
Absolutely. Use Laravel’s `Response` macros or middleware to embed JSON-LD in API responses. For example, extend `JsonResource` to include schema metadata: `public function toArray($request) { return array_merge(parent::toArray($request), ['@context' => 'https://schema.org', '@type' => 'Product']); }`.
What Laravel versions does brick/schema support, and how do I check compatibility?
The package targets PHP 8.1+ and Laravel 9+. Verify compatibility by checking the `composer.json` requirements and the package’s changelog. If using older Laravel versions, ensure your PHP version aligns with the package’s minimum requirements.
How can I validate that my Schema.org markup is correct before deploying to production?
Use Google’s [Rich Results Test](https://search.google.com/test/rich-results) for manual validation. For automated testing, write PHPUnit assertions against the package’s validator or integrate a CI check with tools like `schema-validator` (Node.js) via Laravel’s Artisan commands.
Will brick/schema work with existing SEO plugins like Yoast or All in One SEO?
Yes, but ensure there’s no duplicate schema generation. Disable conflicting plugin features (e.g., Yoast’s schema output) and use brick/schema as the single source of truth. For WordPress-Laravel hybrids, prioritize the package’s output in Blade templates or API responses.
How do I handle Schema.org updates if they break my existing markup?
Monitor Schema.org’s [official changelog](https://schema.org/docs/changes.html) and the package’s release notes. Use feature flags or config-based schema versions to isolate breaking changes. Test updates in staging with the Rich Results Test before production deployment.
Can I generate Microdata/RDFa alongside JSON-LD for the same content in Laravel?
Yes, the package supports multiple formats. For Blade templates, use conditional logic to output Microdata/RDFa for HTML pages and JSON-LD for APIs. Example: `{{ $schema->toMicrodata() }}` in views and `return response()->json($schema->toJsonLd())` in controllers.
What’s the best way to cache schema generation in Laravel for high-traffic sites?
Cache generated schemas using Laravel’s cache drivers (e.g., Redis or file cache). Store serialized JSON-LD in a `schema_cache` table with TTL or use `Cache::remember()`. For dynamic data (e.g., user-generated content), cache at the model level with `cacheFor()`.
Are there performance considerations when generating complex schemas (e.g., nested AggregateRating)?
Complex schemas can impact response times. Optimize by lazy-loading nested properties, caching static schemas, and avoiding redundant validation. Profile with Laravel Debugbar to identify bottlenecks, especially in API routes or high-traffic Blade templates.
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor