Skip to content

Add Middleware feature.enabled, feature.disabled #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 26, 2021

Conversation

dshafik
Copy link
Contributor

@dshafik dshafik commented Feb 7, 2021

This builds on #25 and adds the ability to easily protect routes or controllers using middleware.

From the README:

Middleware

This package includes middleware that will deny routes depending on whether a feature is enabled or not.

To use the middle, add the following to your app/Http/Kernel.php:

protected $routeMiddleware = [
    // other middleware
    'feature.enabled' => \MikeFrancis\LaravelUnleash\Middleware\FeatureEnabled::class,
    'feature.disabled' => \MikeFrancis\LaravelUnleash\Middleware\FeatureDisabled::class,
];

You can then use the middleware in your routes:

Route::get('/new-feature-path', function () {
    //
})->middleware('feature.enabled:myAwesomeFeature');

Route::get('/terrible-legacy-path', function () {
    //
})->middleware('feature.disabled:myAwesomeFeature');

or in your controllers like so:

class ExampleController extends Controller
{
    public function __construct()
    {
        $this->middleware('feature.enabled:myAwesomeFeature');
        // or
        $this->middleware('feature.disabled:myAwesomeFeature');
    }
}

You cannot currently use dynamic strategy arguments with Middleware.

@mxkxf
Copy link
Collaborator

mxkxf commented Feb 25, 2021

@dshafik Just a heads up this needs rebasing or the conflicts resolving. Last one! Thanks for all your hard work.

This adds the ability to easily protect routes or controllers using middleware.

From the README:

This package includes middleware that will deny routes depending on whether a feature is enabled or not.

To use the middle, add the following to your `app/Http/Kernel.php`:

```php
protected $routeMiddleware = [
    // other middleware
    'feature.enabled' => \MikeFrancis\LaravelUnleash\Middleware\FeatureEnabled::class,
    'feature.disabled' => \MikeFrancis\LaravelUnleash\Middleware\FeatureDisabled::class,
];
```

You can then use the middleware in your routes:

```php
Route::get('/new-feature-path', function () {
    //
})->middleware('feature.enabled:myAwesomeFeature');

Route::get('/terrible-legacy-path', function () {
    //
})->middleware('feature.disabled:myAwesomeFeature');
```

or in your controllers like so:

```php
class ExampleController extends Controller
{
    public function __construct()
    {
        $this->middleware('feature.enabled:myAwesomeFeature');
        // or
        $this->middleware('feature.disabled:myAwesomeFeature');
    }
}
```

You cannot currently use dynamic strategy arguments with Middleware.
@dshafik
Copy link
Contributor Author

dshafik commented Apr 26, 2021

@mikefrancis merge conflicts resolved, this one is good to go!

Copy link
Collaborator

@mxkxf mxkxf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dshafik ❤️

@mxkxf mxkxf merged commit 5e54aaa into laravel-unleash:master Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants