- Can Cycle ORM replace Eloquent in a Laravel application without breaking existing queries?
- Cycle ORM can replace Eloquent entirely, but it requires refactoring query logic since its API differs. Start by migrating services/controllers away from Eloquent queries first, then gradually convert models to Cycle-compatible entities. Use tools like `cycle/annotated` to ease the transition. For existing queries, wrap Eloquent’s query builder or replace it incrementally.
- Does Cycle ORM support Laravel’s Scout, Cashier, or Nova integrations?
- Cycle ORM does not natively support Laravel’s Scout, Cashier, or Nova. These features would need custom integrations or wrappers. For example, Scout’s search functionality could be replaced with a custom repository or behavior in Cycle. Check the [Cycle ecosystem](https://cycle-orm.dev/docs) for third-party extensions or build your own using Cycle’s behaviors.
- How does Cycle ORM handle migrations in a Laravel project?
- Cycle ORM provides schema introspection and migration generators via `cycle/migrations`. For Laravel projects, you can replace Eloquent’s migrations with Cycle’s DSL or wrap Laravel’s Schema builder. Greenfield projects benefit most, while legacy schemas may require mapping existing Laravel migrations to Cycle’s format. Use `cycle/schema-renderer` to scaffold migrations from your entities.
- Is Cycle ORM suitable for a Laravel app with simple CRUD operations?
- Cycle ORM is overkill for basic CRUD if your app is lightweight. Eloquent’s simplicity and Laravel integration make it a better fit for simple projects. Cycle shines in complex scenarios like domain-driven design, event sourcing, or long-running processes. If your app grows beyond basic CRUD, Cycle’s flexibility becomes valuable.
- Can Cycle ORM work with Laravel’s service container and dependency injection?
- Yes, Cycle ORM integrates with Laravel’s service container. Bind Cycle’s `EntityManager` and `Repository` to the container via a service provider. Use Laravel’s `bind()` method to resolve Cycle dependencies. Example: `$app->bind('Cycle\ORM\EntityManagerInterface', fn($app) => $app->make('Cycle\ORM\EntityManager'));`
- Does Cycle ORM support polymorphic relations like Eloquent’s `morphTo` and `morphWith`?
- Yes, Cycle ORM supports polymorphic relations via `RefersToMorphed` and `OwnsMorphed`. These relations allow a model to reference multiple entity types, similar to Eloquent’s `morphTo`. Configure them in your entity’s `refersToMorphed()` or `ownsMorphed()` methods. Example: `$entity->refersToMorphed('target', TargetInterface::class);`
- How does Cycle ORM handle transactions in long-running PHP processes like RoadRunner?
- Cycle ORM is designed for long-running processes with an immutable service core and disposable Unit of Work (UoW). Transactions are managed per request or command chain, avoiding memory leaks. Use `cycle/orm`’s `Transaction` class or integrate with Laravel’s transaction manager. For RoadRunner, ensure each request starts a new UoW to maintain isolation.
- What Laravel versions and PHP versions does Cycle ORM support?
- Cycle ORM supports PHP 8.0–8.3 and Laravel 9.x–11.x. Check the [Cycle ORM documentation](https://cycle-orm.dev/docs) for the latest compatibility matrix. For older Laravel versions, use the `1.x` branch of Cycle ORM, but note that some features may be missing. Always test thoroughly in your environment.
- Can I use Cycle ORM with Laravel’s Eloquent models without converting them entirely?
- Yes, you can incrementally migrate Eloquent models to Cycle ORM. Start by replacing queries in services/controllers with Cycle’s `Repository` calls. Gradually add Cycle attributes (e.g., `@Entity`, `@Column`) to models. Use `cycle/annotated` to auto-generate Cycle entities from existing Eloquent models. Avoid mixing Eloquent and Cycle in the same model to prevent conflicts.
- How does Cycle ORM’s query builder compare to Eloquent’s in terms of performance?
- Cycle ORM’s query builder is optimized for performance, especially in long-running processes. It uses a fluent API with eager/lazy loading, partial selects, and custom fetch strategies. Benchmarks show Cycle can outperform Eloquent in complex queries due to its schema-agnostic design and immutable core. For simple queries, the difference is negligible, but Cycle excels in cyclic graphs or deep relations.