payter/has-column-many
A Laravel package adding a hasColumnMany Eloquent relationship for storing related model IDs in a JSON or array column instead of a pivot table, with familiar attach, detach, sync, and query helpers.
1,4,9 / [1,4,9] / serialized PHP) behave like a HasMany relation on an Eloquent model. That lets a PM frame the real trade-off explicitly: normalized pivot table vs. JSON column vs. delimited-ID column, rather than defaulting to "we'll just add a pivot table" in every schema review.whereJsonContains — free, no dependency, limited relation semantics; (b) staudenmeir/eloquent-json-relations — mature, supports inverse relations and query constraints; (c) a pivot table — correct, queryable, integrity-enforced; (d) this package — smallest surface area, lowest adoption. A PM should require the team to price all four before approving option (d).Consider it when all of the following hold:
whereHas, no constrained eager loads — or you plan to filter in PHP.Look elsewhere when:
staudenmeir/eloquent-json-relations covers the JSON case with an ecosystem behind it; native json casts plus whereJsonContains cover the simplest cases with zero dependency.Executives: This is a small, MIT-licensed utility that lets an existing database column — a list of IDs stored as comma-separated text, JSON, or serialized PHP — behave like a normal Laravel relationship. Its business value is deferring or avoiding a data migration, which is where the cost is. It is not a platform decision and should not be standardized on. Recommendation: trial in a time-boxed spike (1–2 days), hold for production. The adoption risk is maintenance, not licensing: one maintainer, one star, no dependents. If it proves useful, vendor the ~single class into our codebase and own it.
Engineering: It buys schema compatibility with legacy data without a migration and without rewriting read paths — the relation surfaces as a familiar Eloquent relationship. The costs are explicit: relation mutations rewrite the full column (lost-update risk under concurrent writes), no SQL-level whereHas constraints, and no referential integrity, so orphan cleanup and deletion cascades become application logic. Benchmark it against staudenmeir/eloquent-json-relations and a plain pivot table before committing; if we adopt, we fork it, add tests, and document the cardinality ceiling we enforce.
Decision framing: Approve as an experiment, not an architecture. Success criteria: one real legacy dataset reads correctly through the relation, write paths are known to be single-writer or queued, and we have a dated plan to migrate to a pivot or JSON-with-integrity model if cardinality or concurrency grows.
How can I help you explore Laravel packages today?