633Innovations

Knowledgebase | Standards


Pennant Feature Flag Implementation Standards

When implementing a new Feature Flag with Pennant, please ensure you are following these standards:

Creating the new Feature Class:

php artisan pennant:feature ManageMailCodes The above command generates the new class inside the \App\Features directory as follows:

<?php

namespace App\Features;

class ManageMailCodes extends Feature
{
    /**
     * Rename the feature's slug.
     */
    public string $name = 'ManageMailCodes'; //You can manually update this to manage.mail.codes
}

The pennant stub file has been modified in order to generate the correct template for each feature created.

After the Feature Class is created, you can use the following directives as feature flags:

Middleware Flag:

  1. Add the pennant EnsureFeaturesAreActive helper class to the route file:
    use Laravel\Pennant\Middleware\EnsureFeaturesAreActive;
    
  2. Add the new Feature class to the route file:
    use App\Features\ManageMailCodes;
    
  3. Add the new middleware check to the middleware list:
    EnsureFeaturesAreActive::using(ManageMailCodes::class)
    
<?php

use Illuminate\Support\Facades\Route;
use Laravel\Pennant\Middleware\EnsureFeaturesAreActive;
use Modules\MailCode\App\Http\Controllers\MailCodeController;
use Modules\MailCode\app\Livewire\Index;
use App\Features\ManageMailCodes;

Route::middleware(['auth', 'verified', EnsureFeaturesAreActive::using(ManageMailCodes::class)])->group(function () {
    Route::resource('mailcode', MailCodeController::class)->except(['index'])->names('mailcode');
    Route::get('mailcode', Index::class)->name('mailcode.index');
});