pennant
pennant copied to clipboard
[1.x] Adds `Feature::activeForAny()`
I want to be able to check if any of a user's related models have a particular feature enabled.
$schools = $user->loadMissing('schools');
$featureIsActive = Feature::for($schools)->someAreActive('enrolled-in-beta');
But this actually is checking that all of the schools have at least one of the features (in this case it's just one feature, 'enrolled-in-beta'
, which is gets wrapped as an array) being passed in. So if all of the user's schools don't have the feature enabled, $featureIsActive
is false.
With the change in this PR, we can accomplish that with:
$featureIsActive = Feature::for($schools)->activeForAny('enrolled-in-beta');
I would have just changed someAreActive()
but it seems like that would be a breaking change (proven by the fact I would have to modify tests) 😢 hence the new method.