clearlyip / laravel-flagsmith
A Flagsmith client for Laravel
Installs: 14 376
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: ^8.2
- flagsmith/flagsmith-php-client: ^4.4.0
- laravel/framework: ^10.44.0 || ^11.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.8.1
- guzzlehttp/psr7: ^2.6.2
- orchestra/testbench: ^8.23.0 || ^9.0.0
- phpunit/phpunit: ^10.5.25
- squizlabs/php_codesniffer: ^3.10.1
- vimeo/psalm: ^5.25.0
README
Laravel-flagsmith was created by, and is maintained by Andrew Nagy, the package is designed to allow Laravel to work with Flagsmith
Features
- Provides a trait to be able to get flags based on Laravel Users (Flagsmith Identities)
- Utilizes Laravel's Queue system to update flags in the background
- Utilizes Laravel's Cache system to store flags in a cache for quick access
- Utilizes Laravel's Task Scheduling system to update flags on a schedule
- Adds a route to utilize Flagsmith's webhooks to update the cache when flags change
Installation & Usage
Requires PHP 8.2+
Require Laravel-flagsmith using Composer:
composer require clearlyip/laravel-flagsmith
Laravel Version Compatibility
Usage
Configuration Files
- Publish the Laravel Flagsmith configuration file using the
vendor:publish
Artisan command. Theflagsmith
configuration file will be placed in yourconfig
directory (Use--force
to overwrite your existingclearly
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 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
Get All Flags for a User
$user = Auth::user(); $flags = $user->getFlags();
Check if flag is enabled for a user
An optional second parameter can be added as the default if the flag does not exist
$user = Auth::user(); $flags = $user->isFlagEnabled('foo');
Get a Flag value for a User
An optional second parameter can be added as the default if the flag does not exist
$user = Auth::user(); $vakue = $user->getFlagValue('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);