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 Null Carbon

Laravel Null Carbon Laravel Package

genealabs/laravel-null-carbon

NullCarbon implements the Null Object pattern for Carbon in Laravel. When a date is missing, it stands in safely so date methods return null instead of throwing errors or defaulting to now, keeping models, Blade views, and formatting logic from breaking on nullable timestamps.

View on GitHub
Deep Wiki
Context7

A Laravel Carbon null-class.

Frequently asked questions about Laravel Null Carbon
How do I install genealabs/laravel-null-carbon?
Install it with composer require genealabs/laravel-null-carbon, then apply the package's trait to the model or base model whose nullable date attributes need protection. There is no service provider, migration, or schema change involved, so adoption is strictly additive and can be done model by model. Because the codebase is small and MIT-licensed, you can read the source before committing to confirm it fits your version matrix.
Does laravel-null-carbon support Laravel 12, PHP 8, and Carbon 3?
The supplied metadata does not confirm PHP 8.x, Laravel 9 through 12, or Carbon 2.x versus 3.x support, and the June 2024 release predates recent Laravel and Carbon majors. Check the package's composer.json constraints first and run a smoke test against your exact versions. Since the codebase is tiny, the whole integration can be de-risked by reading the source before committing.
What does NullCarbon return for format(), toDateTimeString(), or toIso8601String() when the date is null?
NullCarbon answers the Carbon API with benign defaults instead of throwing, so calls like format() return a value rather than failing on null. The exact output for toDateTimeString(), toIso8601String(), jsonSerialize(), toArray(), and __toString() should be verified in the source before you depend on it. Also confirm whether it defaults to now or to a sentinel value, because that affects timezone semantics.
Does laravel-null-carbon work with CarbonImmutable and Eloquent's datetime cast?
CarbonImmutable support and the interaction with $casts = ['field' => 'datetime'] are not confirmed by the available context, so test both paths explicitly. The documented approach is a trait on the model or base model, which behaves more like a custom accessor than a replacement for Eloquent's cast system. Validate it on a scratch model before rolling it out across your app.
Is laravel-null-carbon safe for financial, legal, or audit-critical dates?
No. The dominant risk is semantic: a null object turns missing data into a valid-looking date, which can flow silently into isPast(), diffForHumans(), comparisons, sort ordering, and eligibility checks and produce plausible-but-wrong output instead of a loud failure. For fields with financial, legal, compliance, or audit significance, that is materially worse than a null-pointer error because the bug ships quietly. Use it for presentation and read models, never as a data-integrity control.
Will NullCarbon break my API JSON responses or snapshot tests?
It can. Serialization contracts may change shape because a value that previously serialized as JSON null may become an ISO string, an empty string, or an omitted field, depending on what NullCarbon returns for jsonSerialize() and toArray(). Review every endpoint and test snapshot that consumes nullable dates and assert the exact serialized output before and after adoption.
How can I tell whether a NullCarbon date is actually null?
Check whether the package exposes a documented detection method such as isNull() so call sites can still branch deliberately instead of assuming a value exists. If no such helper is documented, add your own wrapper or a companion boolean attribute on the model. Be careful with existing is_null() and instanceof Carbon checks, because they will silently flip behavior once a NullCarbon object replaces null.
Is genealabs/laravel-null-carbon actively maintained?
The package had a release in June 2024 but shows roughly 56 stars and zero dependents, which is a real bus-factor concern for a dependency. The supplied information does not confirm a CI version matrix or a release cadence. Because it is MIT-licensed with a tiny surface area, forking it or reimplementing a roughly 50 to 100 line custom cast is a credible escape hatch, so decide internally who owns it if upstream stops releasing.
What are alternatives to laravel-null-carbon?
Common alternatives are a custom Eloquent cast or accessor, PHP's nullsafe operator and Blade's optional() helper, or supplying explicit default values at the formatting boundary. A custom cast gives you full control over serialization and detection semantics while keeping the same null-object idea. NullCarbon is convenience rather than infrastructure, so weigh it against a small in-house implementation.
Which fields and use cases is laravel-null-carbon best for?
It fits server-rendered Laravel applications with Blade-heavy presentation, admin and back-office panels, reporting views, and API resources where nullable timestamps such as published_at, approved_at, last_seen_at, cancelled_at, and trial_ends_at are formatted constantly. It removes repetitive null guards without changing how dates are queried, persisted, or validated. It is a poorer fit for API-first or domain-heavy services that depend on missing data failing loudly.
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.
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums
rlacerda83/query-parser
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings