Giter Club home page Giter Club logo

Comments (5)

anon38575347537 avatar anon38575347537 commented on July 28, 2024

'cpf' => 'required|cpf|unique:users'

from validator-docs.

extramicro avatar extramicro commented on July 28, 2024

'cpf' => 'required|cpf|unique:users'

Tentei isso também, mas não valida estoura exception.
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'xxxxxxxxxxx' for key 'cpf' (SQL: update users set cpf = xxxxxxxxxxx, users.updated_at = 2020-06-29 09:22:04 where id = 2)

from validator-docs.

geekcom avatar geekcom commented on July 28, 2024

Olá @extramicro, essa issue não está relaciona a lib, você tá tentando essa validação em um método update certo? Faz o seguinte:

use Illuminate\Validation\Rule;

Validator::make($data, [
    'email' => [
        'required',
        Rule::unique('users')->ignore($user->id),
    ],
]);

Assim você está ignorando a regra unique no update, desta forma essa violação de chave duplicada não acontecerá.

Para mais informações verifique a documentação do Laravel:

Forcing A Unique Rule To Ignore A Given ID:

https://laravel.com/docs/7.x/validation#rule-unique

from validator-docs.

extramicro avatar extramicro commented on July 28, 2024

@geekcom é um método update sim, mas eu não quero ignorar, quero utilizar a validação do CPF dessa lib.

from validator-docs.

danielboso avatar danielboso commented on July 28, 2024

@geekcom estou tendo o mesmo problema. Em um cadastro, estou validando unique cpf e parece que isso é ignorado. Estou utilizando a seguinte rule em um request validator required|cpf|unique:nome_tabela,cpf

from validator-docs.

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.