- 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.