Skip to content

The number field rejects a string that is a number #113

Closed
@lindyhopchris

Description

@lindyhopchris

In the Eloquent package, the Number field only accepts an integer or float. This is correct for JSON because a JSON number decodes to a PHP integer or float.

However, Laravel's integer and numeric validation rules pass with a string that represents a number - because Laravel's validation is loosely-typed. This means that a string number value can pass the validation but then cause an exception to be thrown from the Number field.

We should fix in two ways:

  1. Provide a number validation rule that can be used for a JSON number - ensuring the PHP value is validated as either an integer or float. This should be the recommended way of validating the number field.

  2. We could provide a acceptStrings() method on the number field - when called, the field would also accept a numeric string. Personally I wouldn't use this but it would mean the developer can opt-in to numeric strings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions