You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This package allows instant, zero-deployment toggling of application features.
7
+
Laravel Feature Flags allows instant, zero-deployment toggling of application features.
8
8
9
-
Individual features can be in one of three states:
9
+
The state of each feature flag can be checked from anywhere in the application code (including via a `@feature('name')` blade directive) to determine whether the conditions you set have been met to enable the feature.
10
+
11
+
Each feature can be in one of three states:
10
12
- On: enabled for everyone
11
13
- Off: disabled for everyone
12
-
- Dynamic: evaluated according to a custom or default callback
14
+
- Dynamic: evaluated according to a feature-specific closure (with a fallback option)
13
15
14
16
___
15
17
## Installation
@@ -40,48 +42,21 @@ If you wish to change to a different cache driver, update your `.env`:
40
42
FEATURES_CACHE_STORE=file
41
43
```
42
44
43
-
### Use Your Own Model
44
-
To use your own model, update the config and replace the existing reference with your own model:
45
-
46
-
```php
47
-
// app/config/feature-flags.php
48
-
49
-
'feature_model' => \App\Models\Feature::class,
50
-
```
51
-
52
-
Make sure to also cast the state column to a feature state enum using the `FeatureStateCast`:
53
-
54
-
```php
55
-
// app/Models/Feature.php
56
-
57
-
use Codinglabs\FeatureFlags\Casts\FeatureStateCast;
58
-
59
-
protected $casts = [
60
-
'state' => FeatureStateCast::class
61
-
];
62
-
```
63
-
64
45
## Usage
65
-
Create a new feature in the database and give it a default state:
46
+
Create a new feature in the database and set the initial state:
An example use case of the feature updated event would be if you were caching the result of a dynamic handler and need to clear that cache when a feature is updated.
98
+
You should listen for the `FeatureUpdatedEvent`event if you have any downstream implications when a feature state is updated, such as invalidating any cached items that are referenced in dynamic handlers.
125
99
126
100
___
127
101
## Advanced Usage
@@ -131,12 +105,12 @@ A dynamic handler can be defined in the `boot()` method of your `AppServiceProvi
131
105
use Codinglabs\FeatureFlags\Facades\FeatureFlag;
132
106
133
107
FeatureFlag::registerDynamicHandler('search-v2', function ($feature, $request) {
Dynamic handlers will only be called when a feature is in the `dynamic` state. This will allow you to define custom rules around whether that feature is enabled like in the example above where the user can only access the feature if they have a tester role.
138
112
139
-
Each handler is provided with the features name and current request as arguments and must return a bool value.
113
+
Each handler is provided with the features name and current request as arguments and must return a boolean value.
140
114
141
115
### Default Handler For Dynamic Features
142
116
You may also define a default handler which will be the catch-all handler for features that don't have an explicit handler defined for them:
0 commit comments