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.
P1D, PT30M) in a single column" option viable by hiding the parse/format boilerplate behind an Eloquent attribute cast.CarbonInterval. The real decision is "add a dependency" vs "write 20 lines in app/Casts," which should be judged on maintenance risk, not capability."P1D", 86400, or a humanized string — a cross-team contract that affects mobile, web, and partner integrations.SUM, AVG, comparisons), an ISO string column is painful; that pushes you toward integer seconds in the database with a presentation-layer cast instead. This is a data-model decision a PM should be in the room for.Consider it when:
CarbonInterval instances at the model boundary so feature code (comparisons, add() to dates, humanized display) stays readable.Look elsewhere when:
CastsAttributes; it is small, testable, and removes the dependency entirely.To executives: A tiny open-source helper that eliminates hand-rolled parsing of duration values in our models, standardizing them on ISO 8601. Zero license cost, negligible code footprint. The trade-off is stewardship: it is a low-activity project last released in 2020, so we should treat it as code we adopt and own (vendored or reimplemented) rather than a dependency we rely on for support. Recommendation: use the pattern, own the code.
To engineering: It provides an Eloquent custom cast that round-trips a database string into a CarbonInterval/DateInterval. Before adopting we need to confirm PHP 8.x and current Laravel compatibility, add tests for nulls, zero, week and month units, and malformed input, and decide the column type and length. If any of that is contested, the cast is cheap enough to reimplement in-house with the behavior we actually want — which is likely the better long-term call given the project's activity level.
How can I help you explore Laravel packages today?