atymic/laravel-dateinterval-cast
A Laravel Eloquent cast that converts database values to and from PHP DateInterval objects, letting you store intervals in your models and access them as native DateInterval instances without manual parsing or conversion code.
Decision summary: Do not adopt this as a production Composer dependency. Treat atymic/laravel-dateinterval-cast as a reference implementation and vendor the cast class (~40–80 lines) into the application with internal tests and ownership. Value is in the pattern, not the package.
Architecture fit
CarbonInterval/DateInterval object and serializes it back on write. It sits entirely in the persistence layer and introduces no service provider sprawl, no config surface, and no runtime hooks.HH:MM:SS). Most integration failures here are data-modeling failures, not code failures.CarbonInterval of "P1M" is not a fixed number of seconds. If the business logic needs month-aware or DST-aware arithmetic, the cast is a transport mechanism only and the domain layer must own the math.Integration feasibility
$casts, confirm the column type, write two or three feature tests. A mid-level engineer can validate it in under a day.illuminate/* and nesbot/carbon constraints almost certainly cap at Laravel 7/8 and Carbon 2. On Laravel 10/11/12 with Carbon 3, composer require will either fail outright or silently resolve the whole app back to an older Carbon. That is a fleet-wide blast radius from a 12-star package.CastsAttributes contract has drifted (get/set signatures, cast parameters, the casts() method replacing the $casts property in Laravel 11). None of these are guaranteed to break, but none are covered by the package's test matrix either.Technical risk
P1M as 2,592,000 seconds) will pass tests and then drift. Enforce format at the schema and validation layer, not in the cast.Key questions
P1Y2M3D), integer seconds, or a Postgres INTERVAL? Who owns that decision?forHumans()), or seconds?Stack fit
varchar(64) for ISO 8601 is the safest default; integer seconds if calendar semantics are genuinely unnecessary).Migration path
app/Casts/, add an MIT attribution header, and pin our own signature to the current CastsAttributes interface.null + log).Compatibility
Sequencing
Run this after the schema/format decision and before any feature that consumes intervals. Do not let the cast become the de facto specification of what an interval means — write that down first.
Maintenance
Support
Scaling
CarbonInterval JSON-serializes poorly by default, so expose an explicit toIso8601String() accessor rather than letting the cast object leak into responses.Failure modes
CHECK, and a null-safe accessor.null (unknown) and PT0S (zero) must not be conflated.Ramp-up
How can I help you explore Laravel packages today?