Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#[GreaterThan], #[GreaterThanOrEqualTo], #[LessThan], #[LessThanOrEqualTo] works not as expected (size comparision) #772

Open
isag-clemensbastian opened this issue May 8, 2024 · 0 comments

Comments

@isag-clemensbastian
Copy link

✏️ Describe the bug
Usage of the validation Attributes

  • #[GreaterThan]
  • #[GreaterThanOrEqualTo]
  • #[LessThan]
  • #[LessThanOrEqualTo]

is not fully compatible with the laravel implemetation of the corresponding validation rules. While the laravel documentation allows a field or a comparison value to be passed, the implementation in laravel-data always tries to evaluate the given value as a field reference.

https://laravel.com/docs/11.x/validation#rule-gt
The field under validation must be greater than the given field or value. The two fields must be of the same type. Strings, numerics, arrays, and files are evaluated using the same conventions as the size rule.

The constructor method of those validation rules looks like:

// Spatie\LaravelData\Attributes\Validation\LessThan
public function __construct(
        string|FieldReference $field,
    ) {
        $this->field = $this->parseFieldReference($field);
    }

✅ Expected behavior
When a string is passed to the constructor it is evaluated as a comparision value instead of a field reference.

🖥️ Versions

Laravel: 10+
Laravel Data: 4
PHP: 8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant