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
Doctrine Json Odm

Doctrine Json Odm Laravel Package

dunglas/doctrine-json-odm

Store PHP objects as JSON documents in PostgreSQL JSONB or MySQL JSON columns alongside traditional Doctrine ORM mappings, enabling schema-less, NoSQL-like hybrid data models with fast querying and indexing.

View on GitHub
Deep Wiki
Context7

Doctrine JSON ODM is an Object-Document Mapper for Doctrine ORM that lets you store PHP objects as JSON documents inside relational databases. It combines traditional, efficient relational mappings with schema-less, NoSQL-like data in JSON and JSONB columns of PostgreSQL (>= 9.4) and the JSON column type of MySQL (>= 5.7.8).

  • Seamless integration with Symfony and API Platform—no extra configuration required
  • Query schema-less documents with performance comparable to MongoDB
  • Define indexes on JSON columns for fast lookups
  • Simple Composer install: composer require dunglas/doctrine-json-odm
Frequently asked questions about Doctrine Json Odm
How do I install dunglas/doctrine-json-odm in a Laravel application?
Run composer require dunglas/doctrine-json-odm, then wire Doctrine into Laravel using an integration such as fruitcake/laravel-doctrine. If you use Symfony Serializer for denormalization, configure that bridge as well. Symfony and API Platform users usually need no extra bootstrap, but Laravel requires manual Doctrine and serializer integration.
Does dunglas/doctrine-json-odm support Laravel?
It is not Laravel-native but can be used in Laravel through Doctrine ORM integration such as fruitcake/laravel-doctrine. You must also wire Symfony Serializer if you rely on JSON document denormalization. Laravel compatibility therefore depends on the Doctrine bridge, PHP version, and Symfony component constraints rather than a Laravel-specific package release.
Which databases are supported by Doctrine JSON ODM?
It supports PostgreSQL JSON and JSONB columns from PostgreSQL 9.4 and MySQL JSON columns from MySQL 5.7.8. PostgreSQL is preferred for JSON-heavy workloads because jsonb operators and GIN indexes provide strong querying and indexing. MySQL and SQLite use more generic JSON handling and do not get equivalent jsonb-specific benefits.
What is the difference between JsonDocumentType and JsonbDocumentType?
JsonDocumentType maps documents to a generic JSON column, while JsonbDocumentType targets PostgreSQL jsonb columns. Use JsonbDocumentType when you need PostgreSQL jsonb operators and indexes. MySQL should use the JSON column type rather than PostgreSQL jsonb-specific behavior.
Does v1.5.1 introduce breaking changes or a database migration?
No, v1.5.1 is a patch release with no breaking changes, deprecations, new schema requirements, or DBAL/Doctrine migration changes indicated. It fixes denormalization of typed object collections as Foo[][] with Symfony Serializer 8.1. It is a low-risk upgrade, especially if you use nested typed collections. Pin to 1.5.1 or higher and add a regression test if applicable.
How do I use PostgreSQL jsonb operators and GIN indexes with this package?
Store documents in jsonb columns via JsonbDocumentType and add GIN indexes through Doctrine migrations or native SQL. Query with PostgreSQL jsonb operators using native SQL or DB-specific query builders. The ODM handles document mapping, but index and query design remain database-specific.
What PHP and Doctrine versions are required for v1.5.1?
Existing requirements remain unchanged in v1.5.1, including PHP 8.1+ and Doctrine DBAL/ORM compatibility considerations such as DBAL 4.3.0+ and ORM 3.0+. Confirm exact Composer constraints for your project before upgrading. The patch does not add a new DBAL or ORM migration step.
How should I validate JSON documents stored with Doctrine JSON ODM?
Enforce structure with database constraints, Symfony Validator or JSON Schema, and application-level checks. JSON columns are schema-less, so without validation you risk data drift. Cache validation results where runtime overhead matters.
Is Doctrine JSON ODM safe for production use in a Laravel app?
It can be production-safe if you enforce validation, define appropriate indexes, and test DBAL/ORM upgrades. PostgreSQL jsonb workloads gain the most because of path queries and GIN indexes, while MySQL and SQLite need more generic JSON handling. Keep PostgreSQL-specific query logic behind interfaces or feature flags if portability matters.
What are alternatives to dunglas/doctrine-json-odm?
Alternatives include Doctrine MongoDB ODM for a dedicated document database, native PostgreSQL jsonb columns with custom Doctrine DBAL types, or manual relational modeling with JSON columns. Doctrine JSON ODM is useful when you want document-style storage inside Doctrine ORM and an RDBMS. Choose based on whether you need PostgreSQL JSON indexing, a full document store, or simpler relational schemas.
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