- Can I use spiral/cycle-bridge to fully replace Laravel’s Eloquent ORM with Cycle ORM?
- Yes, the bridge is designed to integrate Cycle ORM as a standalone replacement for Eloquent. You’ll need to configure Spiral’s DI container to bind Cycle’s `EntityManager` and `RepositoryInterface` as primary dependencies, then migrate your models to Cycle’s annotation-driven syntax. The package provides helpers to disable or extend Spiral’s native database layer if needed.
- What Laravel versions does spiral/cycle-bridge support?
- The bridge is built for Laravel applications using Spiral Framework 3.0+ and PHP 8.1+. While it integrates with Laravel’s ecosystem, it primarily relies on Spiral’s modular architecture. Ensure your Laravel app’s dependencies (like PHP-DI) align with Spiral’s requirements, as the bridge acts as a compatibility layer.
- How do I configure Cycle ORM’s database connection in Laravel?
- Extend your Laravel `config/database.php` to include Cycle ORM’s DSN configuration under a new `cycle` connection. The bridge provides Spiral’s config-driven approach to merge Cycle’s annotation paths and DSN settings. Example: `'cycle' => ['dsn' => 'mysql://user:pass@localhost/db', 'annotations' => [__DIR__.'/app/Entities']]`.
- Will this package work alongside Eloquent in the same Laravel app?
- Yes, the bridge supports a hybrid approach where Cycle ORM handles specific entities while Eloquent manages others. Use Spiral’s DI container to bind Cycle’s `EntityManager` for targeted models, leaving Eloquent’s `Model` bindings intact. This requires careful namespace separation and repository interface binding.
- Does spiral/cycle-bridge support Laravel’s migrations system?
- No, the bridge relies on Cycle ORM’s migration tool (`cycle/orm-migrations`) instead of Laravel’s native migrations. You’ll need to generate and run Cycle migrations separately, though you can integrate them into Laravel’s `Artisan` commands via Spiral’s console module. Schema changes are annotation-driven in Cycle.
- How do I handle caching with Cycle ORM in Laravel?
- Cycle ORM lacks built-in caching, so leverage Spiral’s cache decorators (e.g., Redis, APC) to wrap Cycle’s `RepositoryInterface` methods. The bridge provides hooks to inject caching logic into repository operations. For example, cache query results using Spiral’s `CacheInterface` in a decorator around `find()` or `findMany()`.
- Are there performance benchmarks comparing Cycle ORM to Laravel’s Eloquent?
- Cycle ORM is optimized for low overhead and efficient query generation, often outperforming Eloquent in raw speed due to its annotation-driven approach and lack of magic methods. However, benchmarks depend on your schema complexity. The bridge includes tooling to compare query performance between Cycle and Spiral’s native queries during migration phases.
- Can I use Cycle ORM’s repositories with Laravel’s service containers?
- Absolutely. The bridge binds Cycle’s `RepositoryInterface` and `EntityManager` as singletons in Spiral’s DI container, making them available throughout your Laravel app. Use dependency injection to resolve repositories in controllers or services, just like Eloquent models. Example: `public function __construct(private RepositoryInterface $userRepo) {}`.
- What’s the migration path if I’m replacing Spiral’s native DB layer?
- Start with a proof-of-concept: migrate 1–2 critical entity models to Cycle ORM annotations, test CRUD operations, and validate DI bindings. Use Spiral’s event system to map Cycle’s lifecycle hooks (e.g., `onPersist`) to Laravel events. Gradually replace Spiral’s `QueryBuilder` with Cycle’s query language, wrapping legacy queries if needed.
- Are there alternatives to spiral/cycle-bridge for integrating Cycle ORM with Laravel?
- For now, this is the primary bridge, as Cycle ORM is primarily designed for Spiral Framework. Alternatives include manually binding Cycle’s services in Laravel’s container or using a generic ORM adapter like `doctrine/dbal` for hybrid setups. However, the bridge provides the most seamless integration with Spiral’s modular architecture and Cycle’s annotation features.