To purge all features from storage in Laravel Pennant, you can follow these detailed steps:
1. Use the `Feature::purge()` method without arguments
This method removes all stored values for every feature in your storage. Calling it without any parameters purges all feature flags entirely from the storage backend (e.g., database).
php
use Laravel\Pennant\Feature;
Feature::purge();
This is useful when you want to clear all feature flag states, for example, after removing features or making significant changes to feature definitions that require a fresh rollout[5][6].
2. Alternatively, use the Artisan command to purge features
Laravel Pennant provides an Artisan command that can be run from the terminal, which is convenient for production environments where you might not want to modify code directly:
bash
php artisan pennant:purge
Running this command without specifying feature names purges all features from storage. This is helpful as part of deployment pipelines or maintenance scripts[2][5][6].
3. Optional: Purge all features except specific ones
If you want to purge all features except a few, you can use the `--except` option with the Artisan command:
bash
php artisan pennant:purge --except=feature1 --except=feature2
This keeps the specified features intact while purging all others. There is also an `--except-registered` flag to keep all features explicitly registered in your service provider and purge the rest[5][6].
4. Flush the in-memory cache if needed
Since Pennant caches feature flag results in-memory during a request, after purging features from persistent storage, you may want to flush this cache to avoid stale data:
php
Feature::flushCache();
This ensures that subsequent feature checks will fetch fresh data from storage[5][6].
Summary of the steps to purge all features from storage in Pennant:
- Call `Feature::purge()` with no arguments in your code to clear all feature flags.- Or run `php artisan pennant:purge` in the terminal to do the same.
- Optionally, use `--except` flags with the Artisan command to exclude certain features from purging.
- Flush the in-memory cache with `Feature::flushCache()` if necessary.
These methods allow you to completely reset the feature flag states stored by Laravel Pennant, enabling you to clean up or reset feature flags as part of your application's lifecycle management[2][5][6].
Citations:
[1] https://wpwebinfotech.com/blog/laravel-pennant-guide/
[2] https://hackernoon.com/how-to-manage-feature-flags-with-laravel-pennant
[3] https://www.honeybadger.io/blog/a-guide-to-feature-flags-in-laravel/
[4] https://laracasts.com/episodes/2685
[5] https://docs.cornch.dev/en/laravel/10.x/pennant
[6] https://laravel.com/docs/11.x/pennant
[7] https://www.laars.com/images/uploads/products/3178A-WEB.pdf
[8] https://dev.to/saurabh-dhariwal/how-to-manage-feature-flags-with-laravel-pennant-in-2024-1phb