collab-corp / laravel-feature-toggle
Config driven feature toggle for Laravel.
Installs: 513
Dependents: 0
Suggesters: 0
Security: 0
Stars: 26
Watchers: 3
Forks: 3
Open Issues: 0
Type:package
Requires
- illuminate/support: ^5.8|^6.0
Requires (Dev)
- orchestra/testbench: ^3.8|^4.0
- phpunit/phpunit: ^7.0|^8.3
This package is auto-updated.
Last update: 2024-11-13 23:59:19 UTC
README
Contents
Installation
For Laravel ~5
composer require collab-corp/laravel-feature-toggle
As with any package, it's a good idea to refresh composer autoloader.
composer dump-autoload
Configuration
To publish features.php
config file, run the following, vendor:publish
command.
php artisan vendor:publish --provider="\CollabCorp\LaravelFeatureToggle\FeatureToggleServiceProvider"
You may then configure your config to your liking, it is possible to use callbacks or callables strings as values.
Binding callbacks
It can become quite cumbersome with a lot of callbacks in your features config, binding a callback to an alias makes this a breeze.
Feature::bind('evaluation', function ($user, ...$dependencies) { // logic. return (boolean) $result; });
In addition to letting laravel inject dependencies through the container, it is also possible to specify values in a comma seperated list.
In your config...
// config/features.php <?php return [ // ... 'my_feature' => 'env:local,development' ];
In your service provider...
Feature::bind('env', function ($user, array $enviroments) { return app()->enviroment($enviroments); });
And you are ready to go.
Usage
This package adds the @features blade directive, it outputs JavaScript that adds the feature function to the window.
it is also possible to check a feature inside a blade file, like so
@feature('name') // Feature is enabled @else // Feature is disabled @endfeature
In your application code you can simply call
use Feature; Feature::isEnabled('name'); Feature::isDisabled('name');
Evaluating features in JavaScript
To evaluate a feature toggle in your frontend, simply add @features
to your blade file. Likely in your header.
This will add a bool feature(value)
helper to your window.
Testing
composer test
Issues
If you discover any vulnerabilities, please e-mail them to me at jonas.kerwin.hansen@gmail.com.
For issues, open a issue on Github.
License
laravel-feature-toggle is free software distributed under the terms of the MIT license.