illuminate/conditionable
Illuminate/Conditionable provides the Conditionable trait, adding when() and unless() methods to Laravel classes. Run callbacks conditionally without verbose if statements, keeping fluent method chains clean and readable. Lightweight and dependency-free, it ships as part of the Laravel framework.
->when($isEnterprise, ...)) instead of nested if/else ladders. This matters to a PM because conditional sprawl is where regressions and "we forgot the edge case" bugs live.illuminate/conditionable is a read-only split of the official laravel/framework repository (MIT, ~35k stars). The PM-level decision is not "should we buy this?" but "should we stop paying engineers to hand-roll conditional-chaining helpers?" The answer is use the first-party trait and redirect that effort to product work.illuminate/support in any modern Laravel app, there is no migration project, no procurement, no security review gate, and no version-lock risk. It can be adopted inside an existing sprint rather than planned as an initiative.Adopt when:
illuminate/support).when() without dragging in the whole illuminate/support surface.Do not require it directly when: the application already installs illuminate/support — the trait is present already, and an explicit composer require just adds a redundant constraint to maintain. Declare it only if you genuinely need it as a standalone dependency.
Look elsewhere when:
if. Wrapping one branch in when() is ceremony, not clarity.when() returns the same instance on a false condition by design; forcing it to model complex control flow produces code that looks elegant and behaves surprisingly.laravel/framework-sourced split or the framework itself; unvetted reimplementations of a five-line trait are pure downside risk.when() calls.Executives (one paragraph): "This is a small built-in capability of the Laravel framework we already run — MIT licensed, maintained by the Laravel core team, used by essentially every modern Laravel application. It lets engineers write conditional business rules as a single readable chain instead of deeply nested if statements, which measurably reduces the defect rate in rule-heavy features like plan entitlements, regional availability, and beta gating. Cost is zero, adoption requires no migration or vendor contract, and it removes a recurring temptation for engineers to build and maintain bespoke helper code. Recommendation: endorse it as a house standard for branching logic in chainable code, not as a standalone initiative."
Engineering (short brief): "Conditionable gives you when($condition, fn($self) => ...) and, in newer versions, unless(). The closure receives the instance and the method returns the instance regardless of the condition, so chains never break and never return null unexpectedly. It ships inside illuminate/support — do not add a redundant direct dependency unless you're publishing a package that needs it standalone. Use it on Eloquent models, collections, DTOs, jobs, and service objects to flatten nested conditionals; skip it for single branches where if is clearer. Add @method self when(...) to class docblocks where IDE inference matters, since traits can confuse static analysis. Hard rule: pin to the official Laravel source, and never vendor an unofficial reimplementation of a trait the framework already owns."
How can I help you explore Laravel packages today?