1. Go to this page and download the library: Download philspil66/gatekeeper library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
class CMSController extends Controller {
public function getPage($pageSlug) {
// here we are getting our page code from some service
$content = PageService::getContentBySlug($pageSlug);
// here we are showing our page code
return view('layout.pages', compact('content'));
}
}
class CMSController extends Controller {
public function getPage($pageSlug) {
// here we are getting our page code from some service
$content = PageService::getContentBySlug($pageSlug);
// feature flagging here!
if(Gatekeeper::isEnabled('new_super_feature')) {
$content = PageCleanerService::clean($content);
}
// here we are showing our page code
return view('layout.pages', compact('content'));
}
}
// release the feature!
Gatekeeper::enable('new_super_feature');
// hide the feature!
Gatekeeper::disable('new_super_feature');
Gatekeeper::remove('new_super_feature');
<div>This is an example template div. Always visible.</div>
@feature('my_awesome_feature')
<p>This paragraph will be visible only if "my_awesome_feature" is enabled!</p>
@endfeature
<div>This is another example template div. Always visible too.</div>
...
class User extends Authenticatable implements FeaturableInterface
{
use Notifiable, Featurable;
...
$user = Auth::user();
// now, the feature "my.feature" is enabled ONLY for $user!
Gatekeeper::enableFor('my.feature', $user);
// now, the feature "my.feature" is disabled for $user!
Gatekeeper::disableFor('my.feature', $user);
@featurefor('my.feature', $user)
// do $user related things here!
@endfeaturefor
// $role is the admin role!
$role = Auth::user()->role;
...
Gatekeeper::enableFor('my.feature', $role);
...
if(Gatekeeper::isEnabledFor('my.feature', $role)) {
// this code will be executed only if the user is an admin!
}