This repository was archived by the owner on Jun 23, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +81
-1
lines changed Expand file tree Collapse file tree 3 files changed +81
-1
lines changed Original file line number Diff line number Diff line change @@ -118,4 +118,46 @@ Check back later for more features!
118118@endfeatureDisabled
119119```
120120
121- You cannot currently use dynamic strategy arguments with Blade template directives.
121+ You cannot currently use dynamic strategy arguments with Blade template directives.
122+
123+ ### Middleware
124+
125+ This package includes middleware that will deny routes depending on whether a feature is enabled or not.
126+
127+ To use the middle, add the following to your ` app/Http/Kernel.php ` :
128+
129+ ``` php
130+ protected $routeMiddleware = [
131+ // other middleware
132+ 'feature.enabled' => \MikeFrancis\LaravelUnleash\Middleware\FeatureEnabled::class,
133+ 'feature.disabled' => \MikeFrancis\LaravelUnleash\Middleware\FeatureDisabled::class,
134+ ];
135+ ```
136+
137+ You can then use the middleware in your routes:
138+
139+ ``` php
140+ Route::get('/new-feature-path', function () {
141+ //
142+ })->middleware('feature.enabled:myAwesomeFeature');
143+
144+ Route::get('/terrible-legacy-path', function () {
145+ //
146+ })->middleware('feature.disabled:myAwesomeFeature');
147+ ```
148+
149+ or in your controllers like so:
150+
151+ ``` php
152+ class ExampleController extends Controller
153+ {
154+ public function __construct()
155+ {
156+ $this->middleware('feature.enabled:myAwesomeFeature');
157+ // or
158+ $this->middleware('feature.disabled:myAwesomeFeature');
159+ }
160+ }
161+ ```
162+
163+ You cannot currently use dynamic strategy arguments with Middleware.
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace MikeFrancis \LaravelUnleash \Middleware ;
4+
5+ use Closure ;
6+ use Illuminate \Http \Request ;
7+ use MikeFrancis \LaravelUnleash \Facades \Feature ;
8+
9+ class FeatureDisabled
10+ {
11+ public function handle (Request $ request , Closure $ next , string $ featureName )
12+ {
13+ if (Feature::enabled ($ featureName )) {
14+ abort (404 );
15+ }
16+
17+ return $ next ($ request );
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace MikeFrancis \LaravelUnleash \Middleware ;
4+
5+ use Closure ;
6+ use Illuminate \Http \Request ;
7+ use MikeFrancis \LaravelUnleash \Facades \Feature ;
8+
9+ class FeatureEnabled
10+ {
11+ public function handle (Request $ request , Closure $ next , string $ featureName )
12+ {
13+ if (!Feature::enabled ($ featureName )) {
14+ abort (404 );
15+ }
16+
17+ return $ next ($ request );
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments