stephenjude / filament-feature-flags

Filament implementation of feature flags and segmentation with Laravel Pennant.
MIT License
90 stars 12 forks source link

[Feature]: Add Support for name Property to Improve Feature Management and Blade Integration #17

Open chrillep opened 1 day ago

chrillep commented 1 day ago

What happened?

The Filament Feature Flags package does not fully support the name property in feature classes, which leads to two related issues:

  1. Feature Management Panel: When a feature is defined with a name property, the feature title in the management panel displays as “(Feature Deleted).” This occurs because the FeatureSegment model relies on class_exists() to resolve the feature title but does not account for aliases defined by the name property.

  2. Blade Template Integration: Blade directives (@feature) fail to recognize aliases defined via the name property. Instead, fully qualified class names must be used, making feature references verbose and inconsistent with Laravel Pennant’s conventions.

How to reproduce the bug

  1. Feature Management Panel:

    • Define a feature class with a name property:
      
      class EnhancedUserProfiles
      {
      use WithFeatureResolver;

    public $name = 'enhanced-user-profiles'; }

    
    * Create a feature segment:
    * Open the management panel.
    * Observe that the title displays “(Feature Deleted)” instead of the alias.
  2. Blade Template:

    • Use the feature alias in a Blade directive:
      @feature('enhanced-user-profiles')
    • Observe that the directive fails unless the fully qualified class name is used:
      @feature(\App\Features\EnhancedUserProfiles::class)

Package Version

2.1.1

PHP Version

8.3.1

Laravel Version

11.34.2

Which operating systems does with happen with?

macOS, Windows, Linux

Notes

Why is this important? Adding support for the name property improves usability by aligning Filament Feature Flags with Laravel Pennant’s conventions. It allows for cleaner, more intuitive feature references in Blade templates and ensures proper functionality in the management panel.

References:

  1. https://github.com/laravel/pennant/issues/67#issuecomment-1648814395
  2. https://laravel.com/docs/11.x/pennant#:~:text=Customizing%20the%20Stored%20Feature%20Name
  3. https://github.com/stephenjude/filament-feature-flags/blob/55b0611f9cd8a35f291715ba469954b5eef332da/src/Traits/WithFeatureResolver.php
  4. https://github.com/stephenjude/filament-feature-flags/blob/55b0611f9cd8a35f291715ba469954b5eef332da/src/Models/FeatureSegment.php#L53
stephenjude commented 1 day ago

Thanks for pointing this out @chrillep . Can you send a PR?

chrillep commented 11 hours ago

Thanks for pointing this out @chrillep . Can you send a PR?

yeah, sry. I tried fixing it. But could get my head around on how to remove all the title things and use the same nameresolver as laravel pennant. :/

or reverse the nameresolver i mean. Since we need to be able to find the class from the $name variable. not sure if there is an classmap somewhere ? =). Like how enforceMorphMap works. https://laravel.com/docs/11.x/eloquent-relationships#custom-polymorphic-types