cubicmushroom/valueobjects
A small PHP package providing lightweight Value Object classes to model immutable domain values (e.g., IDs, money, email, dates) with validation and type-safety. Useful for cleaner Laravel apps and DDD-style codebases.
Money, Email, UUID). This is a strong fit for Laravel applications requiring strict domain modeling (e.g., e-commerce, finance, or identity systems).string, int, array) and strict validation logic reduce runtime errors, improving maintainability in large codebases.bind()) and Eloquent Models (as attributes or relationships). Example:
$this->app->bind(Money::class, fn() => new Money(100, 'USD'));
JsonValueObject).Http::post()) or API resources for type-safe payloads.nicolopignatelli/valueobjects). Monitor for upstream issues or forks.spatie/value-object, php-value-object) or build custom solutions?illuminate/database or doctrine/dbal.phpunit/phpunit for validation tests.Email, UUID) to test integration.string/int fields in models with value objects.FormRequest) and API resources.money_amount, money_currency).bind() to resolve value objects via the container.Money into amount + currency columns).array instead of ArrayValueObject).| Phase | Task | Tools/Techniques |
|---|---|---|
| Assessment | Audit existing models/DTOs for value object candidates. | Static analysis (PHPStan), code reviews. |
| Setup | Install package, configure autoloading, and basic tests. | Composer, PHPUnit. |
| Pilot | Implement 2–3 value objects in a non-production feature. | Laravel’s bind(), Eloquent accessors. |
| Rollout | Replace DTOs/models with value objects in critical paths. | Feature flags, CI checks. |
| Optimize | Benchmark serialization, adjust database storage. | Laravel Debugbar, Blackfire. |
Money object, validating an Email).| Risk | Mitigation Strategy | Example |
|---|---|---|
| Invalid Data | Strict validation in constructors. | new Email('invalid') throws exception. |
| Serialization Errors | Use JsonSerializable or custom serializers. |
Money::fromArray(['amount' => 100]). |
| Database Corruption | Migrate incrementally; use transactions. | Split Money into two columns. |
| Performance Bottlenecks | Benchmark; optimize serialization. | Cache value objects in Redis. |
| Team Resistance | Pilot with measurable benefits (e.g., fewer bugs). | Track validation errors pre/post. |
Money, Email).How can I help you explore Laravel packages today?