I am trying to create a custom validator in Laravel 5, but stuck after making Resolver. When verification is called:
FatalErrorException 97. In the php line, call the undefined method dpvnice \ Validators \ CustomValidator :: setPresenceVerifier ()
Boot function:
Use validation; Use root; Use Dvvnice \ Validators \ CustomValidator; Brighten \ Support \ ServiceProvider; Class AppServiceProvider Extends ServiceProvider {/ ** * Bootstrap any application services * * @ Return zero * / Public function boot () {$ messages = ['cnpj' = & gt; 'CNPJ Invalado', 'CPF' = & gt; 'CPF Invaldo']; Verifier: Resolver (function ($ translator, $ data, $ rule, $ message) {new custom validator ($ translator, $ data, $ rules, $ message);}); } ...
customValidator class:
& lt ;? Php namespace dpvnice \ validators; Use Verifier; Class CustomValidator Extends Validator {Validate public function CPF ($ attribute, $ CPF, $ parameter) {// If for more information from Verifica (empty ($ cpf)) {return false}} / Elimina possibel mascara $ cpf = Str_replace array (, "/", "-" ".", "", $ CFF); // If the information in the number of Verifica digits is a igual one 11 (strlen ($ cpf)! = 11) {return false; } // Verifica from the sequencias invalidas abaixo // Your Digitize Caso afirmativo, retorna falso else ($ cpf == '00000000000' || $ cpf == '11111111111' $ cpf == '22222222222' || $ cpf = = '33333333333' || $ cpf == '44444444444' $ Cpf == '55555555555' || $ cpf == '66666666666' || $ cpf == '77777777777' || $ cpf == '88888888888' || $ Cpf == '99999999999') {return false; // Calculus OS Digitization Verification for verification // CPF é válido} else {for ($ t = 9; $ t <11; $ t ++) {for ($ d = 0, $ c = 0; $ c & Lt; $ T; $ c ++) {$ d + = $ cpf {$ c} * (($ t + 1) - $ c); } $ D = ((10 * $ d)% 11)% 10; If ($ cpf {$ c}! = $ D} {return false; True} true; }} Function validConpj ($ attribute, $ cnpj, $ parameter) {...}}
Use on code:
public function postAdicionarConvidado (request $ Request) {$ input = input :: all (); $ V = Validation :: Creation ($ Request-> All (), $ this-> Condíndo Rule, $ the-> Condíndo Rule Message); $ V- & gt; Ever ('senha', 'required: same: confirmar-senha | min: 5', function ($ input) {return is_null (user :: where (['email' => gt; input [email ']]) -> first ());}); << Code>
Illuminate \ validation \
mask to your custom verification class
No comments:
Post a Comment