Certainly! If you want to control a feature globally (active/inactive for all users) using Laravel Pennant, the recommended approach is to use the Database Store and set the feature's value globally (without scoping it to a user).
Here’s how you can do it:
1. Use the Database Store
By default, Pennant's database store supports global features. When you set a feature without specifying a scope (like a user), it applies to everyone.
2. Setting a Feature Globally
You can enable or disable a feature for all users like this:
use Laravel\Pennant\Feature;
// Enable the feature for everyone
Feature::activate('your-feature-name');
// Disable the feature for everyone
Feature::deactivate('your-feature-name');
This will store the feature as globally active/inactive in the features table.
3. Checking the Feature
When you check the feature, just do:
if (Feature::active('your-feature-name')) {
// Feature is enabled for everyone
}
No need to pass a user or any scope.
4. No Need for Custom Array Store
You do not need to use the array store or make custom DB queries. Pennant's built-in database store already supports global features out of the box.
5. Managing Features
You can manage these features via artisan commands as well:
php artisan pennant:activate your-feature-name
php artisan pennant:deactivate your-feature-name
Summary:
Just use Feature::activate() and Feature::deactivate() without a scope. Pennant will handle the global state for you, no custom logic required!