Skip to main content
Back to packages
622 GitHub stars

ylsideas/feature-flags

View on GitHub

Description

Feature Flags for Laravel. A Feature flag is at times referred to as a feature toggle or feature switch.

Checking feature accessibility

You can use the accessible method to check if a feature is on or off.

Features::accessible('my-feature') // returns true or false

Blade Views

the @feature blade directive is a simple @if shortcut to hide or display certain parts of the view depending on the state of the feature. A second argument flips the state e.g. it will display the contents of the if statement, if the feature is off.

@feature('my-feature')
<p>Your feature flag is turned on.</p>
@endfeature
 
@feature('my-feature', false)
<p>Your feature flag is turned off.</p>
@endfeature

Routing Middleware

The middleware will cause routes to be blocked if the specified feature does not have the correct state.

You may provide a HTTP Status Code in the event of the route being unavailable by flag as well as being able to provide a message which will be shown the the end user. The message will be run through Laravel's tranlation mechanism allowing you to show different possible messages per language.

Route::get('/', 'SomeController@get')->middleware('feature:my-feature')
Route::get('/', 'SomeController@get')->middleware('feature:my-feature,on')
Route::get('/', 'SomeController@get')->middleware('feature:my-feature,off,404')
Route::get('/', 'SomeController@get')->middleware('feature:my-feature,on,404,feature not available')
Route::get('/', 'SomeController@get')->middleware('feature:my-feature,on,404,translatable.message')

Related Content on Laravel Daily

Video

Recent Courses on Laravel Daily

Laravel 13 Starter Kit Teams and Customizations

10 lessons
33 min

Laravel 13 Eloquent: Expert Level

41 lessons
1 h 34 min

How to Structure Laravel 13 Projects

16 lessons
1 h 32 min read

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.