Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Valueobjects

Valueobjects Laravel Package

funeralzone/valueobjects

PHP 7.1+ value object toolkit for fundamental scalar-based VOs. Provides traits for strings/ints/etc, enums via constants, easy native serialization (fromNative/toNative), and encourages domain validation logic. Includes extension library for complex objects.

View on GitHub
Deep Wiki
Context7

A PHP 7 value objects helper library.

Frequently asked questions about Valueobjects
Does funeralzone/valueobjects work with Laravel 9/10 and PHP 8.2+?
The package officially supports PHP 7.1+, but since its last release was in 2020, it may not fully support PHP 8.2+ features like union types or named arguments. Test thoroughly in your environment, or consider forking for updates. For Laravel 9/10, it should work as a standalone library, but avoid PHP 8.2+ specific syntax in custom value objects.
How do I store value objects like Money or Email in a Laravel database?
Use JSON columns for simplicity (e.g., `json` type in MySQL) or normalize into separate tables for type safety. For Eloquent, implement accessors/mutators (e.g., `getMoneyAttribute()`) or use casts. Avoid raw serialization to avoid losing type safety during retrieval.
Can I replace Laravel’s built-in Validator with this package?
Yes, but it’s often better to coexist. Use value objects for domain-specific logic (e.g., `Email::fromString()`) and Laravel’s Validator for generic rules (e.g., `required`). FormRequests can validate inputs with value objects in `authorize()` or `rules()`, then convert to value objects in controllers.
What’s the best way to test value objects in CI?
Test value objects as pure units with PHPUnit, focusing on edge cases (e.g., invalid emails, negative Money). Mock external dependencies (e.g., database) but avoid mocking the value objects themselves. Use data providers for validation scenarios. Immutable objects reduce flakiness in tests.
How do I create custom value objects beyond the built-in ones (e.g., DateRange)?
Extend the `ValueObject` interface and use traits like `StringTrait` or `NumericTrait` for scalars. For complex types, combine traits or write custom logic in the constructor (e.g., validate ranges). Check the [extensions library](https://github.com/funeralzone/valueobject-extensions) for inspiration.
Will this package slow down my API or database queries?
Minimal overhead for simple objects, but complex nested value objects may impact serialization/deserialization (e.g., JSON payloads). Benchmark in your stack. For databases, JSON columns add slight parsing overhead, while normalized tables improve query performance but increase complexity.
Are there alternatives to funeralzone/valueobjects for Laravel?
For lightweight needs, use custom value objects with `spatie/array-to-object` for DTOs. For DDD, consider `thephpleague/value-object` (more modern) or `moneyphp/money` (financial focus). Laravel’s built-in validation suffices for simple cases, but value objects add domain clarity.
How do I integrate value objects with Laravel Eloquent models?
Use accessors/mutators (e.g., `getEmailAttribute()`) or casts to convert between strings/JSON and value objects. For example: `protected $casts = ['email' => Email::class];`. Avoid storing value objects directly in database columns unless using JSON serialization.
Is this package actively maintained? Should I fork it?
The last release was in 2020, with no PHP 8.x/9.x updates. If you need modern PHP support, fork the repo and update dependencies (e.g., `symfony/assert` for PHP 8.2). Check for open issues or community forks before investing time.
How do I migrate from manual validation (e.g., `filter_var($email)`) to value objects?
Start with non-critical fields (e.g., `Email`, `Percentage`). Replace manual checks in controllers with value objects (e.g., `Email::fromString($request->email)`). Use FormRequests to validate inputs, then convert to value objects in services. Gradually extend to domain logic.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky