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

Value Object Laravel Package

spatie/value-object

Deprecated Spatie package for PHP 8+ data transfer objects. Create typed DTOs from arrays with casting, validation, and attribute mapping (e.g., nested keys). Consider migrating to spatie/laravel-data or cuyz/valinor.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • API/Service Layer Standardization: Enforce consistent data contracts between services, APIs, and frontend/backend components, reducing ambiguity in payloads.
  • Domain-Driven Design (DDD) Adoption: Formalize domain models as immutable value objects to align with DDD principles, improving code clarity and maintainability.
  • Build vs. Buy: Buy for teams needing lightweight, pre-built DTOs without reinventing validation/serialization logic. Build only if requiring highly customized behavior beyond this package’s scope.
  • Migration Strategy: Gradual refactoring of legacy APIs or monoliths into modular DTO-based services, easing future decoupling.
  • Use Cases:
    • API request/response normalization (e.g., GraphQL, REST).
    • Database query result transformation (e.g., Eloquent models → DTOs).
    • Event publishing (e.g., domain events as immutable DTOs).
    • Microservices communication (contract-first design).

When to Consider This Package

Adopt if:

  • Your team uses Laravel/PHP and needs immutable, typed data containers with built-in validation/serialization.
  • You prioritize developer productivity over custom DTO logic (e.g., no need for complex inheritance or runtime property manipulation).
  • Your stack is PHP 8.0+ (v3 requirement) and you can tolerate deprecated maintenance (migrate to spatie/laravel-data or valinor later).
  • You want batteries-included features like:
    • Automatic type casting (e.g., strings → dates).
    • Nested DTO support.
    • Mass assignment protection.
    • JSON/XML serialization/deserialization.

Look elsewhere if:

  • You need active maintenance (this package is archived; fork or migrate).
  • Your use case requires dynamic properties or runtime property generation (e.g., dynamic API schemas).
  • You’re using PHP < 8.0 (v2 is outdated; v3 is the future).
  • You need advanced features like:
    • Circular reference handling (e.g., for deeply nested graphs).
    • Custom serialization formats (e.g., Protocol Buffers).
    • Performance-critical scenarios (this package adds slight overhead vs. raw arrays/objects).
  • Your team prefers alternative ecosystems (e.g., Symfony’s Serializer component, jms/serializer).

How to Pitch It (Stakeholders)

For Executives: "This package lets us standardize how data moves through our system—like a ‘contract’ for APIs, databases, and services. It saves dev time by automating validation and formatting (e.g., turning messy JSON into clean, typed objects), reduces bugs from manual parsing, and makes our code easier to maintain. Think of it as ‘TypeScript for PHP data.’ Upfront cost: minimal (just a Composer install). Long-term payoff: faster development, fewer edge-case bugs, and smoother integrations. We’ll migrate to a maintained alternative later, but this gives us a quick win."

For Engineers: *"Spatie’s DTO package gives us a lightweight, opinionated way to handle data transfer without reinventing wheels. Key benefits:

  • Immutability: No accidental mutations in payloads.
  • Validation: Built-in rules (e.g., required fields, type casting) out of the box.
  • Interop: Works seamlessly with Laravel, APIs, and databases.
  • Future-proof: Easy to swap for spatie/laravel-data or valinor later. Tradeoff: Slight abstraction overhead, but worth it for consistency. Example use case: Replace raw arrays in API responses with typed UserProfileDTO objects—catch errors early and auto-format data."*

For Architects: *"This aligns with DDD by enforcing separation of concerns: DTOs act as a boundary between layers (e.g., API → Service → Domain). It’s a pragmatic choice for teams already using Laravel, offering:

  • Reduced boilerplate: No need to write serializers/validators from scratch.
  • Testability: Immutable objects are easier to mock and verify.
  • Tooling synergy: Plays well with Laravel’s ecosystem (e.g., API resources, Form Requests). Caveat: Not a silver bullet—pair with domain events or CQRS for complex workflows. Migrate to laravel-data post-PoC to avoid tech debt."*
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport