Closed devajmeireles closed 1 year ago
@devajmeireles I think this is already possible. You need to ensure that the class is being registered either explicitly via...
use App\Features\NewDashboard;
Feature::define(NewDashboard::class);
or conventionally via...
Feature::discover();
Then add a public "name" property to the feature with your alias.
namespace App\Features;
class NewDashboard
{
public $name = 'new-dashboard';
// ...
}
Please let me know if this doesn't work and we can open this one up and take another look.
For anyone coming across this issue. Tim's suggestion works.
Laravel Pennant v1.5.0
🥳
Created a pull request to add it to the docs.
Problem
When we choose to use features through classes created with
pennant:feature
, the feature name is composed of the class name:App\Features\NewDashboard
, so when we need to check the feature we need to use the reference to the class:The main problem with this is when we need to check the feature through the blade directives: 🥵
Solution
Considering the class name as a string, it would be possible to generate an alias name from the class name to enable an easier way to reference the feature without having to use the format mentioned above, that way we could interact with the feature in a similar way to when we define it via AppServiceProvider, without using classes.
Class:
...\NewDashboard::class
👉🏻new-dashboard
Class:
...\Vip\NewDashboard::class
👉🏻vip.new-dashboard
Usage
Default Alias
The stub for features generated from
pennant:feature
could contain the$alias
property with the proposed alias value of the feature, according to the class name:Observations:
null
value or the removal of$alias
property could be an option to ignore (don't generate) alias.alias
can be a database column or not, according to what the Laravel team decides.Easy Way
Perhaps if something like this were possible it would result in the suggestion above 👇🏻
Final Words
We know that it is possible to do all of the above mentioned when we choose not to use classes for the features, but this ends up making the AppServiceProvider with a lot of definitions or that we need to create a specific ServiceProvider for this.
Hope this helps,
Thanks.