2017 © Pedro Peláez
 

library laravel-flagger

image

leettech/laravel-flagger

  • Friday, April 20, 2018
  • by josimar-lemos
  • Repository
  • 7 Watchers
  • 7 Stars
  • 107 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 10 Versions
  • 26 % Grown

The README.md

Laravel Flagger

Flagger is a package that has been designed to help you on enabling feature flags in Laravel projects., (*1)

Version Compatibility

Laravel Flagger
5.3.x 1.x.x
5.4.x 2.x.x

Installation

To install through composer, simply add the following in your composer.json file:, (*2)

{
    "require": {
        "leettech/laravel-flagger": "~2.0"
    }
}

And then run composer install., (*3)

Quick Installation

The above installation can also be simplified by using the following command:, (*4)

composer require "leettech/laravel-flagger=~2.0"

Configuration

After installing the Flagger package, register the FlaggerServiceProvider in your config/app.php configuration file:, (*5)

'providers' => [
    // Other service providers...
    Leet\Providers\FlaggerServiceProvider::class,
],

Also, add the Flagger facade to the aliases array in your app configuration file:, (*6)

'aliases' => [
    // Other aliases...
    'Flagger' => Leet\Facades\Flagger::class,
],

Then run the migration script to create features and flaggables tables:, (*7)

php artisan migrate

Publish the package configuration:, (*8)

php artisan vendor:publish --provider="Leet\Providers\FlaggerServiceProvider"

And, in your config/flagger.php configuration file, specify which model will have feature flags associated to it (by default it's set to App\User::class)., (*9)

Usage

First of all, make sure you have inserted your features in the features table in the database. You can use the model Leet\Models\Feature for this:, (*10)

\Leet\Models\Feature::create([
    'name' => 'notifications',
    'description' => 'Notifications feature'
]);

flag

Use \Flagger::flag($flaggable, $feature) to attach a feature to a model:, (*11)

$user = \App\User::first();
\Flagger::flag($user, 'notifications');

You can also add Leet\Models\FlaggerTrait to the model in order to make flagger methods available from it:, (*12)

class User extends Model
{
    use \Leet\Models\FlaggerTrait;
}
$user = \App\User::first();
$user->flag('notifications');

flagMany

Use \Flagger::flagMany($flaggables, $feature) to attach a feature to a collection of models:, (*13)

$users = \App\User::all();
\Flagger::flagMany($users, 'notifications');

hasFeatureEnabled

Anywhere in the application, you can check if a user has access to a feature:, (*14)

if ($user->hasFeatureEnabled('notifications')) {
    doSomething();
}

FlaggerMiddleware

To use the FlaggerMiddleware, you have to declare it in the application kernel:, (*15)

protected $routeMiddleware = [
    // Other middleware...
    'flagger' => \Leet\Middleware\FlaggerMiddleware::class,
];

And on any authenticated route:, (*16)

Route::get('notifications', 'NotificationsController@index')->middleware('flagger:notifications');

or, (*17)

Route::group(['middleware' => 'flagger:notifications'], function () {
    Route::get('notifications', 'NotificationsController@index');
    Route::post('notifications', 'NotificationsController@store')
});

Getting enabled features for a model

By adding Leet\Models\FlaggerTrait to your model, you are able to access its enabled features:, (*18)

// returns the features a user have access to
$user->features;

Flagger command

The flagger command accepts an integer, array, or a path to a csv containing a list of integers and adds a flag to each of them:, (*19)

php artisan flagger notifications 1
// OR
php artisan flagger notifications 1 2 3
// OR
php artisan flagger notifications users.csv
// OR
php artisan flagger notifications users.csv --chunk=100

Be sure to create the flag before attempting to add it to any entity., (*20)

The Versions

20/04 2018

dev-master

9999999-dev

  Sources   Download

The Development Requires

by Josimar Lemos

20/04 2018

v2.1.0

2.1.0.0

  Sources   Download

The Development Requires

by Josimar Lemos

07/03 2018

2.0.x-dev

2.0.9999999.9999999-dev

  Sources   Download

The Development Requires

by Josimar Lemos

07/03 2018

v2.0.1

2.0.1.0

  Sources   Download

The Development Requires

by Josimar Lemos

07/03 2018

v2.0.0

2.0.0.0

  Sources   Download

The Development Requires

by Josimar Lemos

19/10 2017

1.0.x-dev

1.0.9999999.9999999-dev

  Sources   Download

The Development Requires

by Josimar Lemos

19/10 2017

1.1.x-dev

1.1.9999999.9999999-dev

  Sources   Download

The Development Requires

by Josimar Lemos

19/10 2017

v1.1.0

1.1.0.0

  Sources   Download

The Development Requires

by Josimar Lemos

19/10 2017

dev-flagger-command

dev-flagger-command

  Sources   Download

The Development Requires

by Josimar Lemos

29/08 2017

v1.0.0

1.0.0.0

  Sources   Download

The Development Requires

by Josimar Lemos