Laravel-flagsmith was created by, and is maintained by Andrew Nagy, the package is designed to allow Laravel to work with Flagsmith
Requires PHP 8.2+
Require Laravel-flagsmith using Composer:
composer require clearlyip/laravel-flagsmith
Laravel | Laravel Flagsmith |
---|---|
8.x | 1.x |
9.x | 2.x |
10.x | 3.x |
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
It's advised to add the interface Clearlyip\LaravelFlagsmith\Contracts\UserFlags
to your user model. This will give you the ability to access flags directly from your user object.
You can add the following trait Clearlyip\LaravelFlagsmith\Concerns\HasFlagss
to your user model to fulfill the requirements of UserFlags
During initial login user flags are synced through a queue which keeps them as up to date as possible
$user = Auth::user();
$flags = $user->getFlags();
An optional second parameter can be added as the default if the flag does not exist
$user = Auth::user();
$flags = $user->isFlagEnabled('foo');
An optional second parameter can be added as the default if the flag does not exist
$user = Auth::user();
$vakue = $user->getFlagValue('foo');
The Flagsmith Class can be accessed through Laravel's Container. The returned class is simply flagsmith-php-client
$flagsmith = App::make(Flagsmith::class);