Giter Site home page Giter Site logo

theriddleofenigma / laravel-model-validation Goto Github PK

View Code? Open in Web Editor NEW
32.0 32.0 5.0 57 KB

Laravel model validation validates the data on model events. *Only for laravel applications.

Home Page: https://theriddleofenigma.github.io/laravel-model-validation/

License: MIT License

PHP 100.00%
database eloquent eloquent-models laravel laravel-application laravel-framework model model-validation php validation

laravel-model-validation's Introduction

Hi there ๐Ÿ‘‹

I'm a passionate FullStack developer from India ๐Ÿ‡ฎ๐Ÿ‡ณ

About me

  • ๐Ÿ’ผ Lead Software Developer at Heptagon, now merged to ConneqtCorp
  • โค๏ธ I love writing PHP (mostly TALL stack), and building fun experiments on weekends
  • ๐Ÿ”ญ Iโ€™m currently working on my personal website, kumaravel.dev, (in-progress).
  • ๐ŸŒฑ Iโ€™m currently learning ThreeJS and teaching laravel livewire in tamil
  • ๐Ÿ’ฌ Ask me about anything here
  • ๐Ÿ“ซ How to reach me: [email protected]
  • โšก Fun fact: Love to code!

Languages and Tools:

Kumaravel's github stats

Top Repositories



Kumaravel | Twitter

laravel-model-validation's People

Contributors

fossabot avatar kumaravel011 avatar rubenmuehlhans avatar syehan avatar theriddleofenigma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-model-validation's Issues

Validator is not validating the correct data

This code is calling model's toArray() to get the data to validate, but that data does not include hidden attributes. The concept of hidden is to hide attributes from public view; they should be included in the data set for validation. You cant use model's getAttributes() either as that transforms the data to be prepped for the database which changes its form. For example attributes that are set and casted as an array are represented as a string, which will fail if the array validation rule is applied. You cant use model's attributesToArray() as that does not include the default values set in protected $attributes = [..].

Validator::make($this->model->toArray(), $this->rules)

I have a similar internal validation framework to this project. When I ran into this bug I found that every other example and project like this has the same bug. How I solved it was with merging these two arrays. getAttributes() has the defaults and attributesToArray() has the data in the proper casted format.

public function validationData(): array {
    return array_merge($this->getAttributes(), $this->attributesToArray());
}

public function validate(): void
{
    Validator::make($this->validationData(), $this->getRules())->validate();
}

If there is a better solution Id like to know.

some function to bypass validation

Is your feature request related to a problem? Please describe.
I need to define validation rule on every model but some time i need to by pass that

Describe the solution you'd like
Maybe you can add some chaining function to skip validation and use like this

//this is current usage with validation rule enabled
MyModel::create(['name'=>'jhon doe');

//code if validation ignored / skip
MyModel::skipValidation()->create(['name'=>'jhon doe');

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
i try to make pull request but my knowledge its limited caus its using boot() on model i dont know to parsing variable to boot() method

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.