PHPackages                             j-webb/laravel-unleash - 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. [API Development](/categories/api)
4. /
5. j-webb/laravel-unleash

ActiveLibrary[API Development](/categories/api)

j-webb/laravel-unleash
======================

An Unleash client for Laravel

2.10.0(1mo ago)12163.6k↓12.8%16[1 issues](https://github.com/j-webb/laravel-unleash/issues)MITPHP

Since Jun 22Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/j-webb/laravel-unleash)[ Packagist](https://packagist.org/packages/j-webb/laravel-unleash)[ RSS](/packages/j-webb-laravel-unleash/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (9)Dependencies (14)Versions (17)Used By (0)

Laravel Unleash
===============

[](#laravel-unleash)

A simple Unleash component for Laravel. It is compatible with the [Unlesah-hosted.com SaaS offering](https://www.getunleash.io/), [Unleash Open-Source](https://github.com/Unleash/unleash), and [GitLab's Feature Flag system](https://docs.gitlab.com/ee/operations/feature_flags.html), which is built on Unleash.

V2 of this package is a wrapper and extension of the [Unleash PHP SDK](https://docs.getunleash.io/sdks/php_sdk) that is compatible with Laravel.

Getting started
---------------

[](#getting-started)

### 1. Install the Laravel Unleash via Composer

[](#1-install-the-laravel-unleash-via-composer)

```
composer require j-webb/laravel-unleash
```

### 2. Configure

[](#2-configure)

#### Create local configuration (optional)

[](#create-local-configuration-optional)

```
php artisan vendor:publish --provider="JWebb\Unleash\Providers\ServiceProvider"
```

#### Required .env values

[](#required-env-values)

```
# Your Unleash instance endpoint
UNLEASH_URL=https://app.unleash-hosted.com/
```

#### Optional .env values

[](#optional-env-values)

```
# Enable or disable the Laravel Unleash client. If disabled, all feature checks will return false
UNLEASH_ENABLED=true

# For compatibility with Unleash V4, or other authentcation methods. Appends itself to the `Authorization` header for each request
UNLEASH_API_KEY=123456

# Instance id for this application (typically hostname, podId or similar)
UNLEASH_INSTANCE_ID=default

# The Unleash environment name, which can be used to as a parameter for enabling/disabling features for local or development environments
# See: https://docs.getunleash.io/advanced/strategy_constraints#constrain-on-a-specific-environment
UNLEASH_ENVIRONMENT=production

# Automatically registers the client instance with the unleash server
UNLEASH_AUTOMATIC_REGISTRATION=true

# Enable/Disable metrics
UNLEASH_METRICS=true

# Enable/Disable failsafe cache for data
# See: https://docs.getunleash.io/client-specification#system-overview
UNLEASH_CACHE_ENABLED=true
UNLEASH_CACHE_TTL=30
```

#### Setting up the Middleware

[](#setting-up-the-middleware)

The module comes bundled with middleware for you to perform a feature check on routes and/or controllers.

**Laravel 11+ / Laravel 13 (`bootstrap/app.php`)**

```
// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
    $middleware->alias([
        'feature' => \JWebb\Unleash\Middleware\CheckFeature::class,
    ]);
})
```

**Laravel 6–10 (`app/Http/Kernel.php`)**

```
protected $routeMiddleware = [
    ...
    'feature' => \JWebb\Unleash\Middleware\CheckFeature::class,
    ...
];
```

Once registered, you can use this in any area where middleware is applicable. As an example, you could use this in a controller.

```
public function __construct()
{
    $this->middleware('feature:your_feature_name');
}
```

See the [Laravel Docs](https://laravel.com/docs/middleware) for more information.

#### Setting up a custom cache handler

[](#setting-up-a-custom-cache-handler)

If the cache option is enabled, by default the component will use the Laravel Cache module. By utilizing the `UnleashCacheHandlerInterface`, you can create your own PSR-16 compatible implementation and override the `unleash.cache.handler` config value with your handler class.

#### Setting up custom strategies

[](#setting-up-custom-strategies)

To add your own strategy, you can override or create your own Strategies Provider. A `UnleashStrategiesProviderInterface` is included for convenience. Once your custom class is build, you should modify the `unleash.strategy_provider` config value.

#### Overwriting default context provider

[](#overwriting-default-context-provider)

If you want to send more context by default, you can overwrite the `UnleashContextProvider`. Make sure that your class implements the `Unleash\Client\ContextProvider\UnleashContextProvider` interface (to prevent confusion with the UnleashContextProvider in this package, an option would be to alias it). After that, change the config value of `unleash.context_provider` to your custom created class.

Usage
-----

[](#usage)

Checking individual features

```
if (Unleash::isEnabled('your_feature')) {
    // Your feature is enabled
}
```

Using array of features.

```
// List of all features, enabled or disabled
$allFeatures = Unleash::getFeatures();
Result: [
    'toggles' => [
        'feature_1' => [
            'enabled' => true,
            'name' => 'feature_1'
        ],
        'feature_2' => [
            'enabled' => false,
            'name' => 'feature_2'
        ]
    ]
]

// List of all enabled features
$enabledFeatures = Unleash::getFeatures(true);
Result: [
    'toggles' => [
        'feature_1' => [
            'enabled' => true,
            'name' => 'feature_1'
        ]
    ]
]
```

*Note: The result matches that which would be returned from the official [Unleash Proxy](https://docs.getunleash.io/sdks/unleash-proxy) instances. This means you could use your Laravel application as an Unleash Proxy endpoint, which is compatible with the official client-side Unleash Proxy SDKs*

Using middleware on a controller

```
class ExampleController extends Controller
{
    public function __construct()
    {
        ...
        $this->middleware('feature:your_feature');
    }
}
```

Using middleware on a route

```
Route::get('/', function () {
    //
})->middleware('feature:your_feature');
```

Because the component is a wrapper of the official [Unleash Client SDK](https://github.com/Unleash/unleash-client-php), you can pass relevant context to your checks:

```
$context = (new UnleashContext())
    ->setCurrentUserId('some-user-id-from-app')
    ->setIpAddress('127.0.0.1')
    ->setSessionId('sess-123456');
$enabled = Unleash::isEnabled('some-feature', $context);
```

*Note: User ID information is automatically added to the context using the [Laravel Auth module](https://laravel.com/docs/authentication)*

Or get variant information

```
$variant = $unleash->getVariant('nonexistentFeature');
assert($variant->isEnabled() === false);
```

### Blade

[](#blade)

You can use the Unleash Blade directive for checking if a feature is enabled in your Blade templates:

```
@featureEnabled('betaTester')
    You are a beta tester
@endfeatureEnabled
```

Or if a feature is **disabled**:

```
@featureDisabled('betaTester')
    Enroll now to be a beta tester.
@endfeatureDisabled
```

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance91

Actively maintained with recent releases

Popularity43

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 85.3% 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 ~147 days

Recently: every ~274 days

Total

16

Last Release

36d ago

Major Versions

1.2.0 → 2.0.02021-10-07

### Community

Maintainers

![](https://www.gravatar.com/avatar/698b7fde2a3519b7a46ca97e8eca24d45bd4e279ef7a9586b66e751d5bc9bc82?d=identicon)[j-webb](/maintainers/j-webb)

---

Top Contributors

[![j-webb](https://avatars.githubusercontent.com/u/10075167?v=4)](https://github.com/j-webb "j-webb (29 commits)")[![revathixplor](https://avatars.githubusercontent.com/u/152109582?v=4)](https://github.com/revathixplor "revathixplor (2 commits)")[![chrillep](https://avatars.githubusercontent.com/u/1267931?v=4)](https://github.com/chrillep "chrillep (1 commits)")[![dniccum](https://avatars.githubusercontent.com/u/2816415?v=4)](https://github.com/dniccum "dniccum (1 commits)")[![parth-vora7](https://avatars.githubusercontent.com/u/263009169?v=4)](https://github.com/parth-vora7 "parth-vora7 (1 commits)")

### Embed Badge

![Health badge](/badges/j-webb-laravel-unleash/health.svg)

```
[![Health](https://phpackages.com/badges/j-webb-laravel-unleash/health.svg)](https://phpackages.com/packages/j-webb-laravel-unleash)
```

###  Alternatives

[tempest/framework

The PHP framework that gets out of your way.

2.3k37.6k21](/packages/tempest-framework)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.8M674](/packages/shopware-core)[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5226.7k](/packages/simplestats-io-laravel-client)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1349.3k1](/packages/jasara-php-amzn-selling-partner-api)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1239.7k25](/packages/fleetbase-core-api)

PHPackages © 2026

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