- Can I use Pomm ModelManager in a Laravel project without replacing Eloquent entirely?
- Yes, but with trade-offs. ModelManager is designed for Pomm, so full integration requires adopting Pomm’s architecture. For partial use, you could abstract both ORMs behind a unified repository interface (e.g., `ModelRepository`) and migrate modules incrementally. However, Laravel’s Eloquent-specific features (like Scout or Notifications) won’t work natively with Pomm.
- What Laravel versions does Pomm ModelManager support?
- ModelManager itself doesn’t enforce Laravel-specific dependencies, but it requires PHP 8.0+ and works with any Laravel version. If you’re using Laravel’s service container, you’ll need to manually bind Pomm’s components (e.g., `SessionBuilder`) to Laravel’s DI system. The package is framework-agnostic but designed for PHP apps using Pomm.
- How do I migrate existing Eloquent models to Pomm ModelManager?
- Start by auditing your current models—identify CRUD operations, relationships, and queries. Replace Eloquent models with Pomm equivalents (e.g., `User` → `UserModel`) and test transactions, events, and complex queries. Use a hybrid approach during migration: wrap Pomm models in a facade or interface to coexist with Eloquent temporarily. Tools like `pomm-project/cli` can help generate Pomm models from schemas.
- Does ModelManager support PostgreSQL-specific features like JSONB or custom types?
- Yes, ModelManager leverages Pomm’s native PostgreSQL support, including JSONB, arrays, and custom types. You can define model properties to map directly to PostgreSQL types, and the package provides tools to hydrate/serialize complex data structures. For advanced use cases, you can write raw SQL queries alongside ModelManager’s built-in methods.
- How do I handle model events (e.g., created, updated) in Laravel’s observer pattern?
- ModelManager includes hooks and events for lifecycle management (e.g., `onCreate`, `onUpdate`), but they’re not Laravel’s `Observer` pattern. You can manually trigger Laravel events from these hooks or use a service layer to bridge the two. For example, dispatch a `ModelCreated` event in the `onCreate` hook and listen to it in Laravel’s event system.
- What’s the performance difference between ModelManager and Eloquent for bulk operations?
- ModelManager is designed for raw performance, especially with PostgreSQL. Benchmark tests show it often outperforms Eloquent in bulk inserts/updates due to Pomm’s lightweight design and native SQL generation. However, complex joins or aggregations may require manual query tuning. Always test with your specific workload—ModelManager excels in high-throughput, low-latency scenarios.
- Can I use ModelManager with Laravel’s Eloquent relationships (e.g., hasMany, belongsTo)?
- No, ModelManager doesn’t support Eloquent’s relationship conventions. You’ll need to define relationships manually using Pomm’s query builder or write custom methods. For example, a `hasMany` relationship would require a separate query to fetch related records, similar to raw SQL or Doctrine’s associations. This adds flexibility but removes Eloquent’s magic.
- How do I configure transactions with ModelManager in Laravel?
- ModelManager integrates with Pomm’s transaction system, which supports PostgreSQL features like constraint deferral and isolation levels. To use transactions, wrap operations in a `ModelLayer` or manually start a transaction via Pomm’s `Connection`. Example: `$modelLayer->transaction(function () use ($modelLayer) { $modelLayer->persist($entity); })`. Laravel’s `DB::transaction()` won’t work directly—you’ll need to delegate to Pomm’s transaction manager.
- Are there alternatives to ModelManager for PostgreSQL in Laravel?
- If you’re tied to Laravel, Eloquent or Doctrine DBAL are the primary alternatives. For Pomm-specific needs, consider `pomm-project/pomm` alone or `pomm-project/orm` (a lightweight ORM). If you need PostgreSQL features without Pomm, libraries like `spatie/laravel-postgres` or `laravel-postgres` extensions can add PostgreSQL-specific tools to Eloquent. ModelManager is unique for its DDD focus and Pomm integration.
- How do I test ModelManager in a Laravel application?
- Use Laravel’s testing tools (PestPHP or PHPUnit) to mock Pomm’s `Connection` and `ModelLayer`. Test model hydration, queries, and transactions in isolation. For database tests, use PostgreSQL containers (e.g., Laravel Sail) and reset the schema between tests. Property-based testing (e.g., with `pestphp/pest-plugin-factories`) can help validate edge cases in model behavior.