composer require collab-corp/laravel-feature-toggle
As with any package, it's a good idea to refresh composer autoloader.
composer dump-autoload
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.
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.
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');
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.
composer test
If you discover any vulnerabilities, please e-mail them to me at [email protected].
For issues, open a issue on Github.
laravel-feature-toggle is free software distributed under the terms of the MIT license.