spatie / laravel-enum

Laravel support for spatie/enum
https://spatie.be/open-source
MIT License
344 stars 37 forks source link

EnumRule issue with different Enums, same value #93

Open robert-abram opened 2 years ago

robert-abram commented 2 years ago

Hi, When we have 2 different enums and 1 rule EnumRule(EmailScopeEnum::class

/**
@method static self DEFAULT()
**/
EmailScopeEnum {
}

/**
@method static self DEFAULT()
**/
PhoneScopeEnum {
}

When we try to check rule against PhoneScopeEnum::DEFAULT() it's working, because DEFAULT can be resolved also in EmailScopeEnum

I fix this by changing passes function in EnumRule

public function passes($attribute, $value): bool
    {
        $this->attribute = $attribute;
        $this->value = $value;

        if ($value instanceof $this->enum) {
            return true;
        }

        if ($value instanceof Enum && !$value instanceof $this->enum) {
            return false;
        }

        try {
            $this->asEnum($value);

            return true;
        } catch (Throwable $ex) {
            return false;
        }
    }
abdul-rehman-dev commented 1 year ago

Hi,

is this issue is close or not. can I work on it.