PHPackages                             ayup-creative/features - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ayup-creative/features

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ayup-creative/features
======================

Simple feature flag system for Laravel with PHP Attributes support

v1.0.2(3mo ago)06MITPHPPHP ^8.2CI passing

Since Feb 6Pushed 3mo agoCompare

[ Source](https://github.com/Ayup-Creative/laravel-features)[ Packagist](https://packagist.org/packages/ayup-creative/features)[ RSS](/packages/ayup-creative-features/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (6)Used By (0)

Laravel Features
================

[](#laravel-features)

A simple, yet powerful feature flag system for Laravel, utilising PHP Attributes for clean and declarative feature enforcement at both object and method levels.

Features
--------

[](#features)

- **Declarative Enforcement**: Use PHP Attributes to control access to controllers and jobs.
- **Granular Control**: Apply feature gates at the class level or individual method level.
- **Queue Integration**: Automatically prevent jobs from being dispatched or executed if their associated features are disabled.
- **Console Commands**: Easily manage your feature flags via the artisan CLI.
- **Caching**: Performance-optimised with built-in cache support.
- **Flexible Actions**: Define how your application should behave when a feature is disabled (abort, skip, fail, or delay).

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require ayup-creative/features
```

The package will automatically register its service provider and facade.

### Run Migrations

[](#run-migrations)

The package requires a database table to store the state of your feature flags. Run the migrations to create the `feature_flags` table:

```
php artisan migrate
```

### Publish Configuration (Optional)

[](#publish-configuration-optional)

You can publish the configuration file to customise the default state and cache settings:

```
php artisan vendor:publish --tag="features-config"
```

Configuration
-------------

[](#configuration)

The published configuration file `config/features.php` allows you to define:

- `default`: The default state (true/false) for features not found in the database.
- `cache_ttl`: How long (in seconds) the feature states should be cached.

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

You can check if a feature is enabled using the `Features` facade or the `features()` helper:

```
use AyupCreative\Features\Facades\Features;

if (Features::enabled('new-dashboard')) {
    // Show the new dashboard
}

// Or using the helper
if (features()->enabled('new-dashboard')) {
    // ...
}
```

To enable or disable features programmatically:

```
features()->enable('new-dashboard');
features()->disable('old-legacy-module');
```

### Console Commands

[](#console-commands)

Manage your features directly from the terminal:

```
# List all features and their current status
php artisan features:list

# Enable a feature
php artisan features:enable my-feature

# Enable all features
php artisan features:enable --all

# Disable a feature
php artisan features:disable my-feature

#Disable all features
php artisan features:disable --all
```

Attribute-based Enforcement
---------------------------

[](#attribute-based-enforcement)

The true power of this package lies in its use of PHP Attributes to declaratively enforce feature gates.

### Controllers (HTTP Middleware)

[](#controllers-http-middleware)

To protect your routes, first register the middleware alias (if not already handled by the service provider) and apply it to your routes. The package automatically registers the `features` alias.

```
Route::get('/experimental', [ExperimentalController::class, 'index'])
    ->middleware('features');
```

Then, use the `#[Feature]` attribute on your controller or its methods:

```
use AyupCreative\Features\Attributes\Feature;

#[Feature('premium-stats')]
class ExperimentalController extends Controller
{
    public function index()
    {
        return view('stats.experimental');
    }

    #[Feature('beta-export')]
    public function export()
    {
        // This method requires both 'premium-stats' AND 'beta-export' to be enabled
    }
}
```

### Background Jobs (Queue)

[](#background-jobs-queue)

You can prevent jobs from being dispatched or executed based on feature states.

#### Dispatch-time Enforcement

[](#dispatch-time-enforcement)

Prevent a job from even being sent to the queue:

```
use AyupCreative\Features\Attributes\DispatchWhenFeatureEnabled;

#[DispatchWhenFeatureEnabled('email-notifications')]
class SendNotificationJob implements ShouldQueue
{
    // ...
}
```

#### Execution-time Enforcement

[](#execution-time-enforcement)

Prevent a job from running when it is processed by a worker:

```
use AyupCreative\Features\Attributes\Feature;
use AyupCreative\Features\Attributes\Semantic\DelayWhenFeatureDisabled;

#[Feature('data-processing')]
#[DelayWhenFeatureDisabled]
class ProcessDataJob implements ShouldQueue
{
    // ...
}
```

Available Attributes
--------------------

[](#available-attributes)

### Core Attributes

[](#core-attributes)

- `#[Feature('name')]`: Requires the specified feature to be enabled.
- `#[FeatureAll(['feat1', 'feat2'])]`: Requires **all** listed features to be enabled.
- `#[FeatureAny(['feat1', 'feat2'])]`: Requires **at least one** of the listed features to be enabled.
- `#[WhenFeatureDisabled(action: 'abort')]`: Defines the behaviour when a feature is disabled.
    - Actions for HTTP: `abort` (returns 404).
    - Actions for Jobs: `skip` (ignores job), `fail` (fails job), `delay` (releases job back to queue).

### Semantic Attributes

[](#semantic-attributes)

For cleaner code, you can use these semantic wrappers for `WhenFeatureDisabled`:

- `#[SkipWhenFeatureDisabled]`: Equivalent to `action: 'skip'`.
- `#[FailWhenFeatureDisabled]`: Equivalent to `action: 'fail'`.
- `#[DelayWhenFeatureDisabled]`: Equivalent to `action: 'delay'`.

### Metadata Attributes

[](#metadata-attributes)

These attributes are available for documentation and can be accessed via reflection, though they are not enforced by the default evaluator:

- `#[FeatureDeprecated(key: 'old-feat', removeBy: '2024-12-31')]`
- `#[LimitFeatureUsage(max: 100, perSeconds: 3600)]`
- `#[FeatureContext(context: 'user')]`

Testing
-------

[](#testing)

The package includes a comprehensive test suite. To run the tests, use:

```
vendor/bin/phpunit
```

You can also run the tests via compsoer using:

```
composer test
```

Contributing
------------

[](#contributing)

If you wish to contribute to this project, please feel free to submit a pull request or open an issue on the [GitHub repository](https://github.com/ayup-creative/laravel-features). We welcome contributions that improve the codebase, add new features, or enhance the documentation.

Credits
-------

[](#credits)

Developed by Ayup Creative.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance81

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

101d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/494de8188ad97403b72e40e385235a74ef6331aa2710b3727193f646189af9fc?d=identicon)[mykemeynell](/maintainers/mykemeynell)

---

Top Contributors

[![mykemeynell](https://avatars.githubusercontent.com/u/1590190?v=4)](https://github.com/mykemeynell "mykemeynell (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ayup-creative-features/health.svg)

```
[![Health](https://phpackages.com/badges/ayup-creative-features/health.svg)](https://phpackages.com/packages/ayup-creative-features)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[illuminate/broadcasting

The Illuminate Broadcasting package.

7126.5M178](/packages/illuminate-broadcasting)[illuminate/pipeline

The Illuminate Pipeline package.

9346.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
