phl/laravel-sti
phl/laravel-sti brings Single Table Inheritance to Laravel Eloquent. Map multiple model subclasses to one database table using a type column, with automatic class resolution, scoped queries, and familiar Eloquent relationships and behavior for cleaner hierarchical models instead of separate tables.
type column, or five tables?" into a reversible, low-cost decision rather than a schema migration project.WHERE type IN (...) instead of UNIONs across tables. This is a real, if modest, win for analytics and back-office tooling — worth flagging to whoever owns internal reporting.Consider it when:
Look elsewhere (or write your own trait) when:
attributes column will age better.morphTo/morphMany is the right tool, and this package is not a substitute.To executives: This is a small, MIT-licensed open-source helper that lets our Laravel code model a family of similar things in one database table while still giving each type its own class and behavior. It is not a platform or a vendor commitment — it is roughly source code we would otherwise write ourselves. Cost is near zero; the risk is also the reason to be careful: it has 17 GitHub stars, no downstream dependents, and has not been released since April 2020, so we should treat it as code we own rather than a dependency we consume. Recommendation: adopt only inside a bounded feature area, vendor it into our repo, add tests, and pair the decision with a written threshold for when we split the table.
To engineering: The package gives us STI on Eloquent — a base model and a discriminator column, with subclass resolution on hydration — which removes the boilerplate of hand-rolling newFromBuilder overrides and type maps. The trade is that it is unmaintained and last shipped against a 2020-era Laravel, so plan on forking and testing against our current version, and be deliberate about the parts STI does not solve for free: factories, form requests and validation per subtype, eager-loading behavior, and the fact that subtype columns must stay nullable. If the fork cost feels higher than the payoff, a short internal trait gets us 90% of the value with none of the dependency risk — that is a reasonable outcome, and we should decide it on the basis of how many subtypes we actually expect.
How can I help you explore Laravel packages today?