vkovic/laravel-custom-casts
vkovic/laravel-custom-casts provides reusable, class-based custom attribute casts for Laravel Eloquent models, keeping get/set and serialization logic organized, testable, and out of your models—ideal for value objects, arrays, and other complex attribute transformations.
string/int. This package makes the typed option cheap — one cast class per concept, registered in $casts, converting DB values ↔ domain objects on hydrate/save.CastsAttributes classes, (2) adopt a base-class package like this, (3) keep primitives and format at the edges. Package wins only when you want ready-made boilerplate and are on a Laravel version without native custom casts.Consider adopting when:
CastsAttributes interface doesn't exist.get/set conventions with less boilerplate.Look elsewhere / skip when:
update(), bulk where()); model-cast packages don't intercept those.Executives: It's a small, free, MIT-licensed utility that lets us treat things like money, email, and phone numbers as first-class types in code rather than loose strings — fewer formatting/validation bugs and cheaper changes when rules shift (adding a currency, changing phone format). Cost is near zero. The caveat: it's a 2020 package with ~200 stars and no recent releases. So my recommendation is conditional — use it only if we're on an older Laravel version; on current versions the same capability ships with the framework. Exit cost is low: the code is thin and permissively licensed, so we can vendor or replace it quickly.
Engineering: It provides a base class for custom attribute casts — define one class per domain type, register it in $casts, and get consistent hydration/serialization. It cuts boilerplate versus hand-rolled casts, keeps transformation logic in exactly one place, and is straightforward to unit test. Trade-offs: implicit behavior at the model boundary, no coverage for query-builder/bulk writes, and the package is unmaintained. Plan: use native CastsAttributes on Laravel 7+, and treat this as a legacy-compatible stopgap otherwise. Recommendation: adopt only as a documented internal pattern with a named owner — or re-implement the equivalent handful of classes in-house to remove the dependency entirely.
How can I help you explore Laravel packages today?