Skip to main content
Back to packages
624 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