PHP code example of leettech / laravel-flagger

1. Go to this page and download the library: Download leettech/laravel-flagger library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

leettech / laravel-flagger example snippets


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

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

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

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

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

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

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

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

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

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

// returns the features a user have access to
$user->features;
sh
php artisan migrate
sh
php artisan vendor:publish --provider="Leet\Providers\FlaggerServiceProvider"
sh
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