getsidekicker/flagr-feature-laravel
Makes working with Flagr in Laravel a snap
28,630
| Install | |
|---|---|
composer require getsidekicker/flagr-feature-laravel |
|
| Latest Version: | 0.1.0 |
| PHP: | ^8.0 |
| Laravel: | 10 – 13 |
| License: | MIT |
| Last Updated: | Mar 13, 2024 |
| Links: | GitHub · Packagist |
Maintainer: sidekicker
flagr-feature-laravel
Prerequisites
To use this package, you will need to have Flagr installed and accessible
Installation
Publish config
php artisan vendor:publish --tag=flagr-feature-laravel-config
Usage
Block execution
//function
feature_eval('flag',
on: fn(object $attachment) => // do stuff when feature is on,
otherwise: fn(object $attachment) => // do stuff when any other variant isn't matched
)
//alias
app('feature')->eval('flag',
on: fn(object $attachment) => // do stuff when feature is on,
otherwise: fn(object $attachment) => // do stuff when any other variant isn't matched
);
Conditional
//function
if (feature_match('flag')) {
// do feature when feature variant is 'on'
} else {
// do otherwise
}
//alias
//function
if (app('feature')->match('flag')) {
// do feature when feature variant is 'on'
} else {
// do otherwise
}
Context
By default, context is sent to Flagr as part of the evaluation call. This can be used to add constraints against segments.
{
"env": "<Laravel Environment>",
"user": ["<Array representation of currently authed user>"],
"host": "<Host as derived from request or APP_URL env>"
}
Additionally, context can be set. Note that any context will be merged over the default context
feature_add_context([]);
app('feature')->addContext([]);
To ensure that consistent feature treatment is applied across requests, you can supply an optional id
feature_set_id('user_123');
app('feature')->setId('user_123');
// evaluation calls
Creating new feature flag
Flags can be created in the format php artisan feature:create-flag {--name} {--description} [{--tags=*}]. This will use the simple boolean flag type within Flagr
e.g.
php artisan feature:create-flag --name="temp-flag" --description="Create temp flag for feature"
Related Packages
francescomalatesta/laravel-feature
A simple package to manage feature flagging in a Laravel project.
207,110
210
russellhudson/laravel-feature-flags-expanded
A simple package to manage feature flagging in a Laravel project.
1,654
0
Version History
| Version | Released | PHP | License |
|---|---|---|---|
| 0.1.0 | ^8.0 | MIT | |
| 0.0.6 | ^8.0 | MIT | |
| 0.0.5 | ^8.0 | MIT | |
| 0.0.4 | ^8.0 | MIT | |
| 0.0.3 | ^8.0 | MIT | |
| 0.0.2 | ^8.0 | MIT | |
| 0.0.1 | ^8.0 | MIT |