Installation & Configuration
You can install the package via composer:
composer require defstudio/enum-features
Usage
Features can be enabled on any enum by using the DefinesFeatures
trait:
use DefStudio\EnumFeatures\EnumFeatures; enum AppFeature { use DefinesFeatures; // ← simply add this case multi_language; case impersonate; case welcome_email; /* And add your feature resolution code */ //with a single method: protected function resolve(Authenticatable $user = null) { match($this){ case self::multi_language => true, case self::impersonate => $user->isAdmin(), default => false; } } //or with a dedicated method: protected function resolveImpersonate(Authenticatable $user = null){ return $user->isSuperAdmin(); } }
and just register the features in a ServiceProvider boot()
method:
class AppServiceProvider extends ServiceProvider { //.. public function boot(): void { AppFeature::defineFeatures(); } }