- Can I use this package directly in a Laravel project without Symfony?
- No, this package is designed for Symfony and Doctrine ORM, not Laravel’s Eloquent. You’d need to create a custom wrapper or facade to translate Symfony behaviors (like traits and listeners) into Laravel-compatible code. For pure Laravel, consider native Eloquent traits or alternatives like Spatie’s Laravel packages.
- What Laravel versions and PHP versions does this package support?
- The package itself supports modern PHP (8.1+), but Laravel compatibility isn’t natively guaranteed. If using it via Symfony Bridge or API Platform, ensure your Laravel version aligns with the Symfony version the bundle targets. For PHP 8.2+, verify no breaking changes exist in the bundle’s dependencies.
- How do I configure the blameable behavior to track the current user?
- The package requires you to define your User class in Symfony’s configuration (e.g., `config/packages/schvoy_base_entity.yaml`). In Laravel, you’d need to replicate this logic via a custom service provider or adapter, mapping the Symfony User class to Laravel’s Auth system (e.g., `Auth::user()`).
- Are the soft delete and timestamp behaviors identical to Laravel’s Eloquent traits?
- No, they’re implemented for Doctrine ORM and Symfony’s event system. While functionally similar (e.g., `deletedAt`, `createdAt`), the underlying mechanisms differ. For Laravel, you’d lose some features (like automatic Doctrine listeners) unless you build a translation layer or stick to Eloquent’s native `SoftDeletes` and `HasTimestamps` traits.
- Does this bundle add performance overhead compared to Laravel’s native solutions?
- Yes, likely. Symfony’s event-driven architecture and Doctrine’s proxy generation introduce reflection and runtime checks. Laravel’s Eloquent traits are optimized for PHP’s native behavior. Benchmark your use case—if performance is critical, native traits or a lightweight custom solution may be better.
- How do I install and use the base entities in a Laravel + Symfony hybrid project?
- Install via Composer as usual (`composer require schvoy/base-entity-bundle`). In a hybrid stack (e.g., using Laravel Symfony Bridge), configure the bundle in Symfony’s `config/packages/` and extend Symfony entities in shared domain models. For Laravel-specific entities, avoid extending Symfony’s base classes and use traits directly with custom adapters.
- What alternatives exist for Laravel that provide similar base entity functionality?
- For Laravel, consider Spatie’s `laravel-activitylog` (for blameable), `laravel-soft-deletes`, or `spatie/laravel-model-states` for stateful entities. For UUIDs/ULIDs, use `ramsey/uuid` or `ulid/ulid`. If you need Doctrine ORM in Laravel, explore `doctrine/orm` with `laravel-doctrine/orm` or `API Platform` for hybrid setups.
- How do I test entities using this bundle in Laravel?
- Testing requires mocking Symfony’s event system and Doctrine listeners. For pure Laravel, isolate the traits in unit tests using PHPUnit’s mocks. If using Symfony Bridge, test entities in a Symfony test environment with Laravel’s HTTP tests. Expect quirks like Doctrine’s lifecycle callbacks not triggering in Eloquent contexts.
- Can I use this bundle in production with Laravel without breaking changes?
- Only if you fully wrap it in Laravel-compatible code. The bundle’s Symfony dependencies (e.g., `knplabs/doctrine-behaviors`) may conflict with Laravel’s autoloading or service container. Monitor for breaking changes in Symfony’s ecosystem, as Laravel’s PHP version support may diverge. Prefer actively maintained alternatives for production-critical apps.
- How do I migrate from Laravel’s Eloquent traits to this bundle’s behaviors?
- Start by auditing your Eloquent models for reusable patterns (e.g., `SoftDeletes`, `HasTimestamps`). Replace them incrementally: extend Symfony’s base entities for shared domain models or use traits directly in Laravel models. Rewrite model observers/events to match Symfony’s lifecycle callbacks. Test thoroughly—query builders and relationships may behave differently between Doctrine and Eloquent.