Skip to content

Rikj000/Laravel-Flagsmith

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel-flagsmith was created by, and is maintained by Andrew Nagy, the package is designed to allow Laravel to work with Flagsmith

Total Downloads Latest Stable Version License

Features

Installation & Usage

Requires PHP 7.4+

Require Laravel-flagsmith using Composer:

composer require clearlyip/laravel-flagsmith

Laravel Version Compatibility

Laravel Laravel Flagsmith
8.x 1.x
9.x 2.x
10.x 2.1.x

Usage

Configuration Files

  • Publish the Laravel Flagsmith configuration file using the vendor:publish Artisan command. The flagsmith configuration file will be placed in your config directory (Use --force to overwrite your existing clearly config file):
    • php artisan vendor:publish --tag="flagsmith" [--force]

All options are fully documented in the configuration file

User

It's advised to add the trait Clearlyip\LaravelFlagsmith\Concerns\HasFeatures to your user model. This will give you the ability to access features directly from your user object.

During inital login user features are synced through a queue which keeps them as up to date as possible

List All Features for a User

$user = Auth::user();
$features = $user->getFeatures();

Check if feature is enabled for a user

An optional second parameter can be added as the default if the feature does not exist

$user = Auth::user();
$features = $user->isFeatureEnabled('foo');

Get a Features value for a User

An optional second parameter can be added as the default if the feature does not exist

$user = Auth::user();
$features = $user->getFeatureValue('foo');

Accessing

The Flagsmith Class can be accessed through Laravel's Container. The returned class is simply flagsmith-php-client

$flagsmith = App::make(Flagsmith::class);