michael-rubel/nullify
Nullify is a Laravel package that converts empty values to null, helping keep request and model data consistent and making validation and database storage more predictable.
if ($value === '').NULL vs ''. Choosing to persist "no value" as NULL rather than empty string is a schema-level product decision. It affects whereNull() filtering, unique indexes, aggregate/COUNT behavior, and how reporting tools interpret missing data. This package makes that decision cheap to enforce at the boundaries.prepareForValidation, API middleware, CSV/import pipelines, and webhook handlers so downstream domain logic never has to distinguish "absent" from "blank."null vs '' mismatches in conditionals, fewer failed unique constraints, cleaner JSON output contracts.Adopt when:
'' vs null ambiguity.NULL as the canonical "missing" representation in the database and want enforcement at ingestion rather than scattered per-controller checks.Look elsewhere (or write a local helper) when:
'0', 'false', 'N/A', '-', or placeholder sentinels must be treated as null. Generic packages rarely match domain semantics, and silently nulling '0' is a genuine data-loss risk worth verifying explicitly.prepareForValidation() is already in the framework.To executives: This is a small, MIT-licensed utility that standardizes how we store "no value" in our database. The business payoff is downstream: cleaner data for reporting and analytics, fewer intermittent bugs from blank-vs-missing confusion, and more predictable API contracts. Cost is near zero; risk is low but non-zero because it's a low-adoption package — so we'd adopt it as a thin, forkable utility rather than a strategic dependency.
To engineering: Adopt michael-rubel/nullify (or lift its logic into app/Support) to normalize empty input to null at our system boundaries — form requests, API middleware, and import handlers. It removes a recurring class of '' vs null defects and lets queries rely on whereNull(). Two conditions before we merge: (1) confirm and test our definition of "empty" — especially whether '0' and whitespace should be nulled, since generic behavior may not match our domain; (2) wrap it behind our own helper so we can swap or extend it without touching call sites. Given the package's size and adoption profile, treat it as a vetted snippet with tests, not an unexamined dependency.
How can I help you explore Laravel packages today?