Weave 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
Eloquent Json Schema

Eloquent Json Schema Laravel Package

folklore/eloquent-json-schema

Generate JSON Schema definitions directly from your Eloquent models. This package inspects attributes, casts, and relationships to build accurate schemas, making it easy to document APIs, validate payloads, and generate typed clients.

View on GitHub
Deep Wiki
Context7

At a glance

Frequently asked questions about Eloquent Json Schema
What does folklore/eloquent-json-schema actually do?
It is a single Eloquent cast: a model attribute holding a JSON Schema document is hydrated into a typed object instead of a raw array or string. That is a deliberately narrow seam, and it fits applications that already treat schemas as data rather than as files or config. It is not a request validator and it does not enforce anything at the database boundary. Typical fits are form builders, tenant-configurable settings, low-code or workflow definition tables, and API contract registries.
How do I install folklore/eloquent-json-schema in a Laravel app?
Install with composer require folklore/eloquent-json-schema, then register the service provider and facade if your Laravel version does not auto-discover them, and add the cast class to the model's $casts array. The real question is dependency compatibility rather than code complexity, so inspect the illuminate/* constraints in composer.json before anything else. With three stars and zero dependents there is no evidence of anyone running this against a current Laravel or PHP release, so budget a half-day spike instead of a half-hour.
Which Laravel and PHP versions does this package support?
That is not reliably documented from the outside, so read the illuminate/* and PHP constraints in composer.json first. Also check whether the cast implements CastsAttributes (Laravel 7 and later) or the older castable convention, because that caps which framework versions can use it. With zero dependents there are no downstream compatibility reports or fixes to lean on, so you would be the first real user.
Does it validate incoming request payloads against a JSON Schema?
No. The package does not validate inbound payloads against a schema and does not enforce anything at the database boundary. If your goal is rejecting bad inbound requests, use Laravel's json validation rule or a dedicated validator package instead. Any stakeholder expecting general JSON Schema validation support in the validator sense will be disappointed, so clear that expectation early.
Which JSON Schema validator library and draft versions does it use?
The cast almost certainly delegates to a third-party validator such as justinrainbow/json-schema or opis/json-schema, and that library rather than this package determines draft support, $ref resolution, format assertion semantics, and error quality. Confirm which one is pulled in and whether it supports draft-04, draft-07, or 2020-12. The package's age likely pins an old validator major version, which caps what you can build on top of it.
How do I define a schema for a model?
The package is built around configurable per-model schema definitions: you define the mapping once and it introspects attributes, casts, and relationships to produce standard JSON Schema output. In practice you add the cast to the attribute that stores the schema document on that model. Check the README for the exact definition class and cast configuration before writing your own conventions.
Does it support relationships for nested objects?
Yes, relationships are supported so nested object definitions can be derived from related models. Combined with cast-derived property types, that lets one definition serve API documentation, form generation, and typed client generation. Verify the output against a real validator for the specific drafts you target, since nesting depth and $ref behavior depend on the underlying validator library.
What happens if a stored schema document is invalid?
That behavior is underspecified from the outside: it is unclear whether the cast validates, compiles, or merely decodes, whether it fails open or closed, and whether that is configurable per attribute. The failure lands on the read path, so a cast that throws during hydration turns a single malformed row into a 500 on any collection endpoint that touches it. That blast radius is far worse than a write-time validator, so test invalid stored data explicitly before shipping.
Does the cast work with cursor(), chunk(), lazy(), and serialization?
Unknown from the documentation alone, so test it. Confirm the cast survives query-builder hydration paths such as cursor(), chunk(), and lazy(), not just single-model retrieval. Also test toArray(), toJson(), save(), and bulk upsert, because casts that behave well on a single find can fail or serialize differently in collection flows.
Is it maintained, and is it safe to run in production?
The repository has around three stars and zero dependents with a low opportunity score, which reads as no ecosystem pull rather than mild unpopularity. There is no production signal, so no downstream bug reports, CVE exposure data, or compatibility fixes exist to rely on. Check whether the repository is archived or merely dormant, and whether there is a named maintainer who would review a pull request. Adopting it means accepting code ownership; if your schemas live in files or a remote registry, use the validator directly instead.
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.
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo