Coder Social home page Coder Social logo

Comments (4)

luckydonald avatar luckydonald commented on August 29, 2024

Isn't that like a locale issue?

from laravel-data.

rubenvanassche avatar rubenvanassche commented on August 29, 2024

At the moment such a thing is not possible:

  • casts cannot create validation rules
  • rule inferrers will always run and thus create the numeric rule

Something like this (#470) could maybe solve this. Since casts would be able to create their own rules in step one. In step two we could only generate nullable/optional rules and leave the numeric rule generation for what it is. The thing is, implementing that feature is a lot of work, so I'll hope to start soon working on this but it will take time.

As for now, why not overwrite the rules using a custom rules method? That's probably the solution, and why I'm closing this issue. It can be fixed, agreed there are better solutions to this but it will take weeks time before they can be implemented.

from laravel-data.

onlime avatar onlime commented on August 29, 2024

As for now, why not overwrite the rules using a custom rules method? That's probably the solution, and why I'm closing this issue.

Hey @rubenvanassche thanks for the hint. That's a viable workaround, but please tell me what you meant by a custom rules method. Did you mean to introduce a dummy rule that always validates?
I am doing it just with the #[WithoutValidation] attribute, e.g. like this next to my custom casts:

        #[WithoutValidation]
        #[WithCast(CsvCast::class)]
        #[WithTransformer(IdListTransformer::class)]
        public null|array|Optional $contactGroupIds,

The #[WithoutValidation] is basically needed everywhere where I cast some input type to another, or where I allow multiple different types as cast value.

from laravel-data.

rubenvanassche avatar rubenvanassche commented on August 29, 2024

Take a look at this section: https://spatie.be/docs/laravel-data/v3/as-a-data-transfer-object/request-to-data-object#content-rule-attribute after the first attributes.

The rules method always has precedence when generating rules over everything else.

from laravel-data.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.