- What is Cycle ORM and how does it compare to Laravel Eloquent?
- Cycle ORM is a PHP DataMapper, ORM, and data modeling engine for classic and long-running PHP apps. It offers a powerful query builder, flexible schema configuration, dynamic mapping, and rich relation support. Unlike Eloquent's Active Record approach, Cycle uses DataMapper patterns, which can fit complex domain models but has a steeper learning curve. It can work with plain PHP objects and coexist with Laravel through custom service provider bindings.
- How do I install Cycle ORM in a Laravel project?
- Install the package with Composer using composer require cycle/orm. In Laravel you will typically add a service provider that binds Cycle's ORM and EntityManager to the container and configures a Cycle\Database\ConnectionManager. You may also add extensions such as cycle/migrations or cycle/annotated depending on your mapping and migration needs. Plan the integration because Cycle replaces Laravel's Illuminate\Database query layer for the parts of the app it manages.
- Can I use Cycle ORM alongside Eloquent models in Laravel?
- Cycle ORM is designed to coexist with Laravel, but it does not use Eloquent's query builder or Active Record layer. Teams can migrate incrementally by replacing queries in services or controllers with Cycle repositories and gradually converting models to Cycle-compatible entities. Cycle supports plain PHP objects, Active Record, and custom entities, so you can keep Eloquent for simple CRUD while using Cycle for complex domain areas. Expect to refactor query logic and add container bindings for Cycle's ORM and EntityManager.
- Which databases are supported by Cycle ORM?
- Cycle ORM supports MySQL, MariaDB, PostgreSQL, SQL Server, and SQLite with a schema-agnostic design. That makes it suitable for multi-database setups and applications that need to target different database engines. The database layer is configured through Cycle's connection manager rather than Laravel's default database abstraction. You should verify driver-specific features and migration behavior for your chosen database.
- Is Cycle ORM a good fit for Laravel Octane or long-running daemon apps?
- Yes, Cycle ORM is specifically designed for long-running and daemonized PHP applications such as RoadRunner and CLI daemons. It has an immutable service core and a disposable Unit of Work, which helps avoid state leaking between requests or jobs. For Laravel Octane or similar setups, you still need to integrate it carefully with the framework container and lifecycle. Its design is a strength for long-running processes compared with ORMs that assume a fresh request per execution.
- How does Cycle ORM handle migrations and schema changes in Laravel?
- Cycle provides schema introspection, scaffolding, and migration generation through extensions such as cycle/migrations. In a Laravel app you can use Cycle's migration tools or wrap Laravel's Schema builder, but you should avoid mixing migration ownership for the same tables. Greenfield projects can adopt Cycle migrations directly, while legacy schemas may require mapping Laravel migrations to Cycle's DSL. Plan schema ownership early to prevent conflicting migration histories.
- Can Cycle ORM manage polymorphic and many-to-many relations?
- Cycle ORM supports has-one, has-many, many-through-many, and polymorphic relations, including cyclic references such as RefersToMorphed. It also supports eager and lazy loading, embedded entities, and custom fetch strategies. These features make it suitable for complex domain models and graph-like data structures. You configure relations in the mapping schema and can use annotations or PHP 8 attributes depending on your setup.
- What are the main drawbacks of using Cycle ORM in Laravel?
- Cycle ORM has a steeper learning curve than Eloquent, especially for teams unfamiliar with DataMapper patterns or Spiral's ecosystem. It replaces Laravel's Illuminate\Database layer, so Eloquent-specific features like Scout, Cashier, or Nova may need custom integrations. For simple CRUD applications, Cycle's flexibility can add unnecessary complexity. The main trade-off is giving up Laravel-idiomatic query patterns in exchange for more powerful modeling and long-running process support.
- How should I test a Laravel application that uses Cycle ORM?
- You can test Cycle ORM like any repository layer by using an in-memory or test database supported by Cycle, such as SQLite, and running your migrations or schema setup before each test. Because Cycle uses a Unit of Work and EntityManager, tests should create or reset those services per test case to avoid state leakage. For integration tests, bind a test connection manager and ORM instance in Laravel's container. Keep query and mapping tests separate from HTTP tests so failures are easier to diagnose.
- What is new in Cycle ORM 2.18.1 and do I need to upgrade?
- Cycle ORM 2.18.1 is a patch release containing a single bug fix in PR #576: children are now retained when a nullable collection is reordered. It introduces no breaking changes, no new public API surface, and no deprecations. If you build sortable or reorderable collection relations, treat this fix as a required baseline rather than an optional patch. The defect class matters because ordered collection reordering can silently drop and reinsert data, so upgrading is low-risk and recommended.