Weave 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
Laravel Value Objects

Laravel Value Objects Laravel Package

michael-rubel/laravel-value-objects

Laravel Value Objects offers an abstract base class and Eloquent casts for turning model attributes into immutable value objects, with validation, comparison helpers, and PHP 8 support for cleaner, type-safe domain code.

View on GitHub
Deep Wiki
Context7

It is an example template for Laravel packages. Fill or change it the way you like.

Frequently asked questions about Laravel Value Objects
How do I install michael-rubel/laravel-value-objects in a Laravel app?
Install it with composer require michael-rubel/laravel-value-objects. Package auto-discovery means there is no service provider to register, no migrations to run, and no config file to publish for baseline use. A proof of concept is typically a one to two engineer-day spike, while a bounded production slice is closer to a sprint. The real work is not the install but deciding the canonical form of each value you plan to wrap.
Which PHP and Laravel versions does laravel-value-objects support?
The package targets PHP 8 and later, and release 7.0.2 explicitly runs CI against PHP 8.4, so the forward-runtime story is reasonably good. Laravel 11 and 12 support should be confirmed directly from the composer.json constraints rather than inferred from the release notes, which only evidence the PHP test matrix. Check that constraint before committing to an upgrade plan on a newer Laravel release.
How do value objects work with Eloquent casts in Laravel?
The package provides an abstract value object base class plus Eloquent casts, letting you turn model attributes into immutable value objects instead of raw scalars. That keeps normalization and validation next to the attribute definition and gives typed parameters on actions and services. Adoption can be incremental and reversible, one attribute at a time. Because the cast changes what is stored, verify legacy rows against the new cast before rolling it out broadly.
What happens when a value object receives invalid input?
That depends on the validation failure semantics — whether you get a thrown exception or a boolean result — and this is the single most important behavior to confirm before wiring up any write path. A thrown exception surfaces as a 500 unless you catch and convert it, while a boolean or validation-rule approach maps naturally to a 422 response. Write an explicit test for each value object you adopt so the failure mode is a deliberate decision rather than an accident.
Can I use it to normalize emails and phone numbers to a canonical format?
Yes, this is exactly the normalization and validation primitive use case the package is aimed at, but the canonical form is your decision: case-folding for emails, E.164 for phones, trimming for names. Confirm the chosen form matches what already exists in the database and in your API contracts before enabling the cast. Mixed legacy data that fails the new cast, and columns sized for unnormalized input, are the two most likely production incidents.
Is laravel-value-objects a replacement for spatie/laravel-data or DTOs?
No. Treat it as a normalization and validation primitive that slots into the domain and edge layers, not as a domain layer or a DTO framework. It does not replace DTO packages or enum-based domain modelling, and it imposes very little architectural structure. The main attraction is that it is swappable, so it should not become load-bearing for your application architecture.
How do I serialize value objects to JSON, queues, and cache keys?
Serialization is the subtle risk area: queue payloads, JSON API resources, and cache keys each need a defined representation of the wrapped value. Rather than trusting undocumented behavior, assert the JSON encoding, the queue round-trip, and the cache key string in your own tests for each value object you adopt. Defining that representation early avoids hard-to-trace breakage later.
Is the Number value object safe to use for arithmetic or money-like values?
Be careful. A sign-handling bug shipped in 7.0.1 and was fixed in 7.0.2 by a community contributor, which tells you signed inputs were not covered by the test suite. A defect like that surfaces as an off-by-a-minus in an invoice, refund, or ledger delta. Treat any arithmetic-bearing value object here as unverified and assert your own expectations instead of trusting upstream green builds.
Is laravel-value-objects production-ready and well maintained?
It is a single-maintainer package from a prolific author, which is a positive signal for competence and a negative one for per-package long-term attention. With roughly 205 stars and zero dependents, there is very little public battle-testing, so you would be an early adopter rather than a follower. The 7.0.2 release merged and credited an outside contributor, a mild positive for triage responsiveness. Mitigate the bus factor by keeping adoption incremental, reversible, and covered by your own tests.
How do I upgrade from 7.0.1 to 7.0.2, and is it a breaking change?
The upgrade is drop-in with no breaking changes, new features, or deprecations, so pin ^7.0.2 in your composer.json and expect no migration work. The negative-number fix in the Number value object is a behavior change only for callers relying on the previous incorrect arithmetic. If you have no such callers, 7.0.2 is a clean adoption point.
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.
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle
glavweb/api-bundle
glavweb/admin-bundle
adachsoft/api-version-bundle
elsayed85/laravel-api-exceptions
ouhssini/laravel-demo-mode
daworks/ncloud-outbound-mailer-driver
gp247/cms
ignibyte/aic-gates
nexa-merchant/blog
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
cgv/localized-resource