Skip to content

Feature Usage seems to be wrong #30

@jimiero

Description

@jimiero

Hello @mckenziearts ,

I think this method here may be wrong

public function canUseFeature(string $featureSlug): bool
    {

        $featureValue = $this->getFeatureValue($featureSlug);

        $usage = $this->usage()->byFeatureSlug($featureSlug)->first();

        if ($featureValue === 'true') {
            return true;
        }

        // If the feature value is zero, let's return false since
        // there's no uses available. (useful to disable countable features)
        if (! $usage || $usage->expired() || $featureValue === null || $featureValue === '0' || $featureValue === 'false') {
            return false;
        }

        // Check for available uses
        return $this->getFeatureRemainings($featureSlug) > 0;
    }

why will it fail if there's not usages done already ?

lets say user purchase a plan with feature "contacts" with limit 30

Then if you do

$user->subscription->canUseFeature('contacts')

it will return false, because he never made use of that feature...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions