thisismahabadi/laravel-feature-flags
最新稳定版本:1.0.8
Composer 安装命令:
composer require thisismahabadi/laravel-feature-flags
包简介
This package helps you implement feature flags in your Laravel application without a 3rd party service.
关键字:
README 文档
README
This package helps you implement feature flags in your Laravel application without a 3rd party service.
Installation
composer require thisismahabadi/laravel-feature-flags
How does it work?
So it's simply using two database tables and trait (src/Traits/FeatureFlag.php) to check if the accessor (user, team, agency, etc.) has access to the requested resource or not.
Tables are:
feature_flags (to store the feature itself including its name and the date which determines the availability date.)
feature_flag_permissions (that stores which accessors [or whatever you specify] have access to what features)
After having the information in the database, all you need to do is to use the mentioned trait in any classes you want, for example, there is also a Middleware (src/Http/Middleware/CheckFeatureFlagAccess.php) which is using that trait, and you can also use it to secure your routes. To assign middleware to routes, do something like this:
Route::middleware('feature_flag:whatsapp')->post('api/v1/whatsapp', WhatsAppController@sendMessage);
The logic of the feature flag trait is that firstly it checks the feature_flags table that if the feature is valid and if so, it'll then check the feature_flag_permissions table to see if the accessor which is requesting has a correlated record in the database.
Configuration
If you execute Laravel's vendor:publish command, your file will be copied to the specified publish location, and then the configurations can be customized.
php artisan vendor:publish --tag=feature-flags-config
Code requirements
This part is only being used if you want the Middleware of this package.
By default, this package is using featureAccessor() belongsTo relation in the User's model as an accessor resource, and if that relation can not be found it will use the user_id who requests an endpoint.
But, Did you know you can also use another resource that you use in your company? Such as team_id, agency_id, customer_id or whatever you use.
Example for using agency_id:
public function featureAccessor(): BelongsTo { return $this->belongsTo(Agency::class, 'agency_id', 'id'); }
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-06