PHPackages                             tojoo/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. tojoo/laravel-unleash

ActiveLibrary[API Development](/categories/api)

tojoo/laravel-unleash
=====================

An Unleash client for Laravel

2.9.0(10mo ago)00[1 PRs](https://github.com/tojoo-dev/laravel-unleash/pulls)MITPHP

Since May 15Pushed 10mo agoCompare

[ Source](https://github.com/tojoo-dev/laravel-unleash)[ Packagist](https://packagist.org/packages/tojoo/laravel-unleash)[ RSS](/packages/tojoo-laravel-unleash/feed)WikiDiscussions v2 Synced 1mo ago

READMEChangelog (2)Dependencies (7)Versions (5)Used By (0)

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

[](#laravel-unleash)

A simple Unleash component for Laravel. It is compatible with the [Unleash-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 Laravel Unleash via Composer

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

```
composer require tojoo/laravel-unleash
```

### 2. Configure

[](#2-configure)

#### Create local configuration (optional)

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

```
php artisan vendor:publish --provider="Tojoo\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 authentication 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 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.

```
#/app/Http/Kernel.php
protected $routeMiddleware = [
    ...
    'feature' => \Tojoo\Unleash\Middleware\CheckFeature::class,
    ...
];
```

Once added to your `Kernel.php` file, 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 built, 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 an 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/8.x/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

28

—

LowBetter than 54% of packages

Maintenance54

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.8% 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 ~211 days

Total

3

Last Release

306d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2aac238e8055b77226ac9f883c719da2796e5d5982a94ee7c7bc2ede8a791697?d=identicon)[k1rana](/maintainers/k1rana)

---

Top Contributors

[![j-webb](https://avatars.githubusercontent.com/u/10075167?v=4)](https://github.com/j-webb "j-webb (31 commits)")[![k1rana](https://avatars.githubusercontent.com/u/80017838?v=4)](https://github.com/k1rana "k1rana (3 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/tojoo-laravel-unleash/health.svg)

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

###  Alternatives

[commercetools/commercetools-sdk

The official PHP SDK for the commercetools Composable Commerce APIs

19281.5k](/packages/commercetools-commercetools-sdk)[j-webb/laravel-unleash

An Unleash client for Laravel

11153.8k](/packages/j-webb-laravel-unleash)[simplestats-io/laravel-client

Client for SimpleStats!

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

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

1344.8k1](/packages/jasara-php-amzn-selling-partner-api)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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