Skip to content

Commit d411ae5

Browse files
committed
update readme
1 parent 32fdb4b commit d411ae5

File tree

1 file changed

+57
-62
lines changed

1 file changed

+57
-62
lines changed

README.md

Lines changed: 57 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
1-
# Dynamic feature flags for laravel.
1+
# Dynamic Feature Flags for Laravel
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/codinglabsau/laravel-feature-flags.svg?style=flat-square)](https://packagist.org/packages/codinglabsau/laravel-feature-flags)
44
[![Test](https://github.com/codinglabsau/laravel-feature-flags/actions/workflows/run-tests.yml/badge.svg)](https://github.com/codinglabsau/laravel-feature-flags/actions/workflows/run-tests.yml)
55
[![Total Downloads](https://img.shields.io/packagist/dt/codinglabsau/laravel-feature-flags.svg?style=flat-square)](https://packagist.org/packages/codinglabsau/laravel-feature-flags)
66

7-
This package offers the ability to implement feature flags in your application which can be easily toggled on or off. You can also set a feature to a dynamic state where you can define custom rules around whether that feature is enabled or not.
7+
This package allows instant, zero-deployment toggling of application features.
8+
9+
Individual features can be in one of three states:
10+
- On: enabled for everyone
11+
- Off: disabled for everyone
12+
- Dynamic: evaluated according to a custom or default callback
13+
814
___
915
## Installation
1016

11-
### Install With Composer:
12-
17+
### Install With Composer
1318
```bash
1419
composer require codinglabsau/laravel-feature-flags
1520
```
1621

1722
### Database Migrations
18-
1923
```bash
2024
php artisan vendor:publish --tag="feature-flags-migrations"
2125
php artisan migrate
2226
```
2327

24-
### Publish Configuration:
25-
28+
### Publish Configuration
2629
```bash
2730
php artisan vendor:publish --tag="feature-flags-config"
2831
```
2932

33+
### Set Your Cache Store
34+
This package caches the state of features to reduce redundant database queries. The cache is expired whenever the feature state changes.
3035

31-
### Cache Store
32-
update your `.env`:
33-
```php
36+
By default, this package will use the default cache configured in your application.
37+
38+
If you wish to change to a different cache driver, update your `.env`:
39+
```
3440
FEATURES_CACHE_STORE=file
3541
```
36-
Note that under the hood this package uses the `rememberForever()` method for caching and that if you are using the `Memcached` driver, items that are stored "forever" may be removed when the cache reaches its size limit.
3742

3843
### Use Your Own Model
39-
4044
To use your own model, update the config and replace the existing reference with your own model:
4145

4246
```php
@@ -58,7 +62,6 @@ protected $casts = [
5862
```
5963

6064
## Usage
61-
6265
Create a new feature in the database and give it a default state:
6366
```php
6467
Feature::create([
@@ -99,47 +102,6 @@ if (FeatureFlag::isEnabled('search-v2')) {
99102
}
100103
```
101104

102-
#### Sharing features with UI (Inertiajs example)
103-
```php
104-
// config/app.php
105-
106-
'features' => [
107-
[
108-
'name' => 'search-v2',
109-
'state' => \Codinglabs\FeatureFlags\Enums\FeatureState::dynamic()
110-
]
111-
],
112-
```
113-
114-
```php
115-
// app/Middleware/HandleInertiaRequest.php
116-
117-
Inertia::share([
118-
'features' => function () {
119-
return collect(config('app.features'))
120-
->filter(fn ($feature) => FeatureFlag::isEnabled($feature['name']))
121-
->pluck('name');
122-
}
123-
]);
124-
```
125-
126-
```javascript
127-
// app.js
128-
129-
Vue.mixin({
130-
methods: {
131-
hasFeature: function(feature) {
132-
return this.$page.features.includes(feature)
133-
}
134-
}
135-
})
136-
```
137-
```html
138-
<!-- SomeComponent.vue -->
139-
140-
<div v-if="hasFeature('search-v2')">Some cool new feature</div>
141-
```
142-
143105
### Updating A Features State
144106

145107
To change a features state you can call the following methods:
@@ -163,9 +125,7 @@ An example use case of the feature updated event would be if you were caching th
163125

164126
___
165127
## Advanced Usage
166-
167128
### Dynamic Features
168-
169129
A dynamic handler can be defined in the `boot()` method of your `AppServiceProvider`:
170130
```php
171131
use Codinglabs\FeatureFlags\Facades\FeatureFlag;
@@ -179,7 +139,6 @@ Dynamic handlers will only be called when a feature is in the `dynamic` state. T
179139
Each handler is provided with the features name and current request as arguments and must return a bool value.
180140

181141
### Default Handler For Dynamic Features
182-
183142
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:
184143

185144
```php
@@ -191,7 +150,6 @@ FeatureFlag::registerDefaultDynamicHandler(function ($feature, $request) {
191150
An explicit handler defined using `registerDynamicHandler()` will take precedence over the default handler. If neither a default nor explicit handler has been defined then the feature will resolve to `off` by default.
192151

193152
### Handle Missing Features
194-
195153
Features must exist in the database otherwise a `MissingFeatureException` will be thrown. This behaviour can be turned off by explicitly handling cases where a feature doesn't exist:
196154

197155
```php
@@ -202,21 +160,58 @@ FeatureFlag::handleMissingFeaturesWith(function ($feature) {
202160

203161
If a handler for missing features has been defined then an exception will **not** be thrown and the feature will resolve to `off`.
204162

205-
## Testing
163+
### Sharing features with UI (Inertiajs example)
164+
```php
165+
// config/app.php
206166

167+
'features' => [
168+
[
169+
'name' => 'search-v2',
170+
'state' => \Codinglabs\FeatureFlags\Enums\FeatureState::dynamic()
171+
]
172+
],
173+
```
174+
175+
```php
176+
// app/Middleware/HandleInertiaRequest.php
177+
178+
Inertia::share([
179+
'features' => function () {
180+
return collect(config('app.features'))
181+
->filter(fn ($feature) => FeatureFlag::isEnabled($feature['name']))
182+
->pluck('name');
183+
}
184+
]);
185+
```
186+
187+
```javascript
188+
// app.js
189+
190+
Vue.mixin({
191+
methods: {
192+
hasFeature: function(feature) {
193+
return this.$page.features.includes(feature)
194+
}
195+
}
196+
})
197+
```
198+
```html
199+
<!-- SomeComponent.vue -->
200+
201+
<div v-if="hasFeature('search-v2')">Some cool new feature</div>
202+
```
203+
204+
## Testing
207205
```bash
208206
composer test
209207
```
210208

211209
## Security Vulnerabilities
212-
213210
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
214211

215212
## Credits
216-
217213
- [Jonathan Louw](https://github.com/JonathanLouw)
218214
- [All Contributors](../../contributors)
219215

220216
## License
221-
222217
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

0 commit comments

Comments
 (0)