PHP code example of stephenjude / filament-feature-flags
1. Go to this page and download the library: Download stephenjude/filament-feature-flags 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/ */
stephenjude / filament-feature-flags example snippets
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
\Stephenjude\FilamentFeatureFlag\FeatureFlagPlugin::make()
]);
}
namespace App\Features;
use Stephenjude\FilamentFeatureFlag\Traits\WithFeatureResolver;
class WalletFunding
{
use WithFeatureResolver;
}
namespace App\Features;
use Stephenjude\FilamentFeatureFlag\Traits\WithFeatureResolver;
class WalletFunding
{
use WithFeatureResolver;
protected bool $defaultValue = false;
}
namespace App\Features;
use Stephenjude\FilamentFeatureFlag\Traits\WithFeatureResolver;
class WalletFunding
{
use WithFeatureResolver;
protected function defaultValue(mixed $scope): bool
{
return false;
}
}
use Stephenjude\FilamentFeatureFlag\Events\{FeatureActivatedForAll,FeatureDeactivatedForAll,FeatureSegmentCreated,FeatureSegmentModified,FeatureSegmentRemoved,RemovingFeatureSegment};
protected $listen = [
FeatureActivatedForAll::class => [
// Dispatched after feature is activated for all users.
],
FeatureDeactivatedForAll::class => [
// Dispatched after feature is deactivated for all users.
],
FeatureSegmentCreated::class => [
// Dispatched after feature segment is created.
],
FeatureSegmentModified::class => [
// Dispatched after feature segment is modified.
],
RemovingFeatureSegment::class => [
// Dispatched before feature segment is removed.
],
FeatureSegmentRemoved::class => [
// Dispatched after feature segment is removed.
],
];
return [
// This package supports only class based features.
/*
* This is the default state for all class based features and
* state will be used if there is no segmentation.
*/
'default' => true,
/*
* Default scope: User::class, Team::class
*/
'scope' => App\Models\User::class,
/*
* Column names and data source that can be used to activate or deactivate for a segment of users.
* This columns must exist on the users table and the data source must be a model.
* COLUMN: The column name as defined on the default scope model config.
* MODEL: The eloquent model of the source table.
* VALUE: The column to be used as value.
* KEY: The column to be used as key.
*/
'segments' => [
[
'column' => 'email',
'source' => [
'model' => App\Models\User::class,
'value' => 'email',
'key' => 'email',
],
],
],
'panel' => [
/*
* Navigation group for admin panel resource.
*/
'group' => 'Settings',
/*
* Navigation item label for admin panel resource.
*/
'label' => 'Manage Features',
/*
* Resource title for admin panel resource.
*/
'title' => 'Manage Features & Segments',
/*
* Navigation item icon for admin panel resource.
*/
'icon' => 'heroicon-o-cursor-arrow-ripple'
]
];