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
Doctrine Adoption

Doctrine Adoption Laravel Package

benkle/doctrine-adoption

Adds a small Collector + Doctrine metadata listener to enhance inheritance mapping by “adopting” child entities into a parent with a named association. Register the loadClassMetadata listener manually (including for schema creation/CLI tools).

View on GitHub
Deep Wiki
Context7

A small set of classes to make doctrines inheritance mapping more useful

Frequently asked questions about Doctrine Adoption
Can benkle/doctrine-adoption work with Laravel Eloquent, or is it strictly for Doctrine ORM?
This package is designed for Doctrine ORM, not Eloquent. While Laravel uses Doctrine DBAL under the hood, Eloquent’s inheritance is limited to single-table inheritance (STI). If you need class-table inheritance or mapped-superclass strategies, you’ll need to explicitly add `doctrine/orm` and integrate this package. Eloquent’s built-in features won’t benefit from it.
How do I install and set up benkle/doctrine-adoption in a Laravel project?
Install via Composer: `composer require benkle/doctrine-adoption`. Then manually configure a `Collector` to define parent-child relationships and attach a `MetadataListener` to Doctrine’s `loadClassMetadata` event. You’ll also need to set up a custom `doctrine` CLI tool for schema generation, as the listener isn’t auto-registered.
What Laravel versions and PHP versions does this package support?
The package requires PHP 8.0+ and is compatible with Laravel 9+ due to its reliance on Doctrine ORM’s modern features. Ensure your Laravel project meets these requirements, especially if you’re adding `doctrine/orm` explicitly for this package.
Does this package support single-table inheritance (STI) like Eloquent, or only class-table inheritance?
This package focuses on class-table inheritance and mapped-superclass strategies, which Eloquent doesn’t natively support. If you’re using Eloquent’s STI, this package won’t replace it but can complement it for more complex inheritance hierarchies when using Doctrine ORM alongside Laravel.
How do I handle schema generation and migrations with this package in Laravel?
Since the `MetadataListener` isn’t auto-registered, you’ll need a custom `doctrine` CLI tool or modify Laravel’s migration logic to account for the inheritance mappings. Schema drift risks arise if migrations aren’t updated to reflect the package’s changes, so test thoroughly in a staging environment.
Are there any performance concerns with class-table inheritance in this setup?
Class-table inheritance can introduce N+1 query risks, especially if queries span parent and child tables. This package doesn’t address performance optimizations, so you’ll need to implement custom repository logic, DQL optimizations, or eager-loading strategies to mitigate these issues.
Can I use this package without adding Doctrine ORM to my Laravel project?
No, this package requires Doctrine ORM (`doctrine/orm`) because it relies on the `EntityManager` and `EventManager` systems. Laravel’s Eloquent and Doctrine DBAL alone won’t suffice. If you’re not already using Doctrine ORM, adding it solely for this package may introduce unnecessary complexity.
What are the alternatives to benkle/doctrine-adoption for inheritance in Laravel?
For Eloquent, stick with single-table inheritance (STI) via `$inherits` in models. For more advanced needs, consider polymorphic relationships, model observers, or accessors/mutators. If you’re using Doctrine ORM, alternatives include custom inheritance mapping in YAML/XML or annotations, though this package provides a cleaner API for runtime adoption.
How do I test inheritance mappings with this package in Laravel?
Test by verifying entity hydration across inheritance levels, querying parent/child relationships, and ensuring schema consistency. Use Laravel’s testing tools to mock the `EntityManager` and `EventManager`, and validate that queries return expected results for both parent and child entities.
Will this package conflict with existing Doctrine listeners or Laravel events?
Potential conflicts can arise if other packages or custom code attach listeners to Doctrine’s `loadClassMetadata` event. Review your existing event listeners and ensure the `MetadataListener` from this package is registered last or prioritized correctly. Laravel’s event system can coexist, but Doctrine-specific configurations require careful ordering.
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.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
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