PHPackages                             shieldforce/package-auto-validation-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. shieldforce/package-auto-validation-laravel

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

shieldforce/package-auto-validation-laravel
===========================================

Validacoes de formularios automatizadas

013.5kPHP

Since Dec 25Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Shieldforce/package-auto-validation-laravel)[ Packagist](https://packagist.org/packages/shieldforce/package-auto-validation-laravel)[ RSS](/packages/shieldforce-package-auto-validation-laravel/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependenciesVersions (2)Used By (0)

[![](https://camo.githubusercontent.com/927f3bfb4be3517629539941559fa0e58eba47a821cd94a7e870b49135d67f64/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f7468756d622f392f39612f4c61726176656c2e7376672f3132303070782d4c61726176656c2e7376672e706e67)](https://camo.githubusercontent.com/927f3bfb4be3517629539941559fa0e58eba47a821cd94a7e870b49135d67f64/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f7468756d622f392f39612f4c61726176656c2e7376672f3132303070782d4c61726176656c2e7376672e706e67)

[Licença Owner](https://shieldforce.com.br/licenca)

Pacote de Auto Validation para Laravel
--------------------------------------

[](#pacote-de-auto-validation-para-laravel)

Neste repositório está o pacote de validação automática!!

- Link do Pacote :

```
https://packagist.org/packages/shieldforce/package-auto-validation-laravel

```

- Instruções de Instalação:

```
composer require shieldforce/package-auto-validation-laravel

```

- Adicionando Provider ao arquivo config/app.php:

```
\ShieldForce\AutoValidation\Providers\AutoValidationServiceProvider::class,

```

- Adicionando o Trait e Request na Classe do Model:

```
use ShieldForce\AutoValidation\Traits\TraitStartInterception;
use Illuminate\Http\Request;

```

- Dê um use no Trait dentro da Classe do Model:

```
use TraitStartInterception;

```

- Copie esse código abaixo e cole no seu Model (Exemplo de Implementação):

###### Esse método que faz a mágica, tudo que você validar nos métodos boot: (creating, created, saved, saving, updated, updating, retrieved, deleted, deleting, restored, restoring)

[](#esse-método-que-faz-a-mágica-tudo-que-você-validar-nos-métodos-boot-creating-created-saved-saving-updated-updating-retrieved-deleted-deleting-restored-restoring)

```
public static function rulesCustom(Request $request)
{
    return
        [
            "request"    => $request,
            "creating"   =>
                [
                    "validations" =>
                        [
                            "first_name"    => ["required", "string", "max:50"],
                            "last_name"     => ["required", "string", "max:50"],
                            "email"         => ["required", "string", "email", "max:100", "unique:users"],
                            "password"      => ["required", "string", "min:4", "confirmed"],
                        ],
                    "messages" =>
                        [
                            "first_name.required" => "Primeiro nome é obritatório",
                            "last_name.required"  => ":attribute nome é obritatório",
                        ]
                ],
            "retrieved:login"   =>
                [
                    "validations" =>
                        [
                            "email"         => ["required", "string", "email", "max:100"],
                            "password"      => ["required", "string"],
                        ],
                    "messages" =>
                        [
                            //
                        ]
                ],
        ];
}

```

###### Tratamento na View - Adicione este trecho de código em algum lugar do seu código (Lembrando que é preciso ter as libs jquery e bootstrap para que funcione perfeitamente):

[](#tratamento-na-view---adicione-este-trecho-de-código-em-algum-lugar-do-seu-código-lembrando-que-é-preciso-ter-as-libs-jquery-e-bootstrap-para-que-funcione-perfeitamente)

```
{{-- Include Toast CSS and JS --}}

@if (count($errors) > 0)

		$.toast( {
			heading   : 'Atenção ao(s) seguinte(s) erro(s):' ,
			text      : [
				@foreach ($errors->all() as $error)
					"{{ $error }}" ,
				@endforeach
			] ,
			icon      : 'error' ,
			hideAfter : false ,
			position  : 'top-right' ,
		} )

@endif

```

##### Publicar Arquivos JS e CSS - Rode o comando

[](#publicar-arquivos-js-e-css---rode-o-comando)

```
php artisan vendor:publish --tag=public --force

```

##### No caso do retorno de erros de validação, se a requisição for feita em php o retorno é esse:

[](#no-caso-do-retorno-de-erros-de-validação-se-a-requisição-for-feita-em-php-o-retorno-é-esse)

```
return back()
    ->with('errorValidation', 'Validação de Campos não passou!!')
    ->withErrors($validator)
    ->withInput()
    ->throwResponse();

```

##### No caso do retorno de erros de validação, se a requisição for feita em javascript o retorno é esse (Neste caso você mesmo fará o tratamento de erros no retorno do seu AJAX, etc..):

[](#no-caso-do-retorno-de-erros-de-validação-se-a-requisição-for-feita-em-javascript-o-retorno-é-esse-neste-caso-você-mesmo-fará-o-tratamento-de-erros-no-retorno-do-seu-ajax-etc)

```
return response()->json([
    'code'       => 301,
    'status'     => "error",
    'message'    => "Validação de Campos não passou!!",
    'data'       => [
        "errorValidation" => $validator->errors()
    ],
], 301)->throwResponse();

```

###### No arquivo resources/lang/pt\_BR/validation.php podemos configurar as mensagens de retorno, trocar nomes de atributos, etc...:

[](#no-arquivo-resourceslangpt_brvalidationphp-podemos-configurar-as-mensagens-de-retorno-trocar-nomes-de-atributos-etc)

```
return [

    /*
    |--------------------------------------------------------------------------
    | Validation Language Lines
    |--------------------------------------------------------------------------
    |
    | The following language lines contain the default error messages used by
    | the validator class. Some of these rules have multiple versions such
    | as the size rules. Feel free to tweak each of these messages here.
    |
    */

    // recaptcha - Guilherme Ferro
    'recaptcha' => 'O campo :attribute não está correto.',

    'accepted'             => 'O :attribute deve ser aceito.',
    'active_url'           => 'O :attribute não é uma URL válida.',
    'after'                => 'O :attribute deve ser uma data depois :date.',
    'alpha'                => 'O :attribute só podem conter letras.',
    'alpha_dash'           => 'O :attribute só podem conter letras, números e traços.',
    'alpha_num'            => 'O :attribute só pode conter letras e números.',
    'array'                => 'O :attribute deve ser uma matriz.',
    'before'               => 'O :attribute deve ser uma data antes :date.',
    'between'              => [
        'numeric' => 'O :attribute deve situar-se entre :min e :max.',
        'file'    => 'O :attribute deve situar-se entre :min e :max kilobytes.',
        'string'  => 'O :attribute deve situar-se entre :min e :max characters.',
        'array'   => 'O :attribute deve ter entre :min e :max itens.',
    ],
    'boolean'              => 'O :attribute campo deve ser verdadeira ou falsa.',
    'confirmed'            => 'O :attribute confirmação não corresponde.',
    'date'                 => 'O :attribute não é uma data válida.',
    'date_format'          => 'O :attribute não coincide com o formato :format.',
    'different'            => 'O :attribute e :other deve ser diferente.',
    'digits'               => 'O :attribute deve ser :digits dígitos.',
    'digits_between'       => 'O :attribute deve situar-se entre :min e :max dígitos.',
    'dimensions'           => 'O :attribute tem dimensões de imagem inválidos.',
    'distinct'             => 'O :attribute campo tem um valor duplicado.',
    'email'                => 'O :attribute deve ser um endereço de e-mail válido.',
    'exists'               => 'O selecionado :attribute é inválido.',
    'filled'               => 'O :attribute campo é obrigatório.',
    'image'                => 'O :attribute deve ser uma imagem.',
    'in'                   => 'O selecionado :attribute é inválido.',
    'in_array'             => 'O :attribute campo não existe no :other.',
    'integer'              => 'O :attribute deve ser um número inteiro.',
    'ip'                   => 'O :attribute deve ser um endereço IP válido.',
    'json'                 => 'O :attribute deve ser uma cadeia JSON válido.',
    'max'                  => [
        'numeric' => 'O :attribute não pode ser superior a :max.',
        'file'    => 'O :attribute não pode ser superior a :max kilobytes.',
        'string'  => 'O :attribute não pode ser superior a :max characters.',
        'array'   => 'O :attribute não pode ter mais de :max itens.',
    ],
    'mimes'                => 'O :attribute deve ser um arquivo do tipo: :values.',
    'min'                  => [
        'numeric' => 'O :attribute deve ser de pelo menos :min.',
        'file'    => 'O :attribute deve ser de pelo menos :min kilobytes.',
        'string'  => 'O :attribute deve ser de pelo menos :min characters.',
        'array'   => 'O :attribute deve ter pelo menos :min itens.',
    ],
    'not_in'               => 'O selecionado :attribute é inválido.',
    'numeric'              => 'O :attribute deve ser um número.',
    'present'              => 'O campo :attribute deve estar presente.',
    'regex'                => 'O :attribute formato é inválido.',
    'required'             => 'O campo :attribute é necessário.',
    'required_if'          => 'O campo :attribute é necessária quando :other é :value.',
    'required_unless'      => 'O campo :attribute é necessária a menos :other é in :values.',
    'required_with'        => 'O campo :attribute é necessária quando :values é present.',
    'required_with_all'    => 'O campo :attribute é necessária quando :values é present.',
    'required_without'     => 'O campo :attribute é necessária quando :values não está presente.',
    'required_without_all' => 'O campo :attribute é requerido quando nenhum :values estão presentes.',
    'same'                 => 'O :attribute e :other devem corresponder.',
    'size'                 => [
        'numeric' => 'O :attribute deve ser :size.',
        'file'    => 'O :attribute deve ser :size kilobytes.',
        'string'  => 'O :attribute deve ser :size characters.',
        'array'   => 'O :attribute deve conter :size itens.',
    ],
    'string'               => 'O :attribute deve ser uma string.',
    'timezone'             => 'O :attribute deve ser uma zona válida.',
    'unique'               => 'Este :attribute já foi registrado.',
    'url'                  => 'O :attribute formato é inválido.',

    /*
    |--------------------------------------------------------------------------
    | Custom Validation Language Lines
    |--------------------------------------------------------------------------
    |
    | Here you may specify custom validation messages for attributes using the
    | convention "attribute.rule" to name the lines. This makes it quick to
    | specify a specific custom language line for a given attribute rule.
    |
    */

    'custom' => [
            'attribute-name' => [
                'rule-name' => 'custom-message',
            ],
            'first_name' => [
                'required'                            => 'Campo :attribute é obrigatório',
                'integer'                             => 'Campo :attribute deve ser um inteiro',
                'min'                                 => 'Campo :attribute deve conter a data mínima de 2000',
                'max'                                 => 'Campo :attribute deve conter a data máxima de 2050',
            ],
        ],

    /*
    |--------------------------------------------------------------------------
    | Custom Validation Attributes
    |--------------------------------------------------------------------------
    |
    | The following language lines are used to swap attribute place-holders
    | with something more reader friendly such as E-Mail Address instead
    | of "email". This simply helps us make messages a little cleaner.
    |
    */

    'attributes' => [
            'g-recaptcha-response'                 => 'reCAPTCHA',
            'first_name'                           => 'Primeiro Nome:',
        ],

];

```

- Exceção - Caso não queira validar um requisição especifica passe no request:

```
$request["not_validation"] === "yes";

```

Equipe
------

[](#equipe)

Alexandre Ferreira do Nascimento

License
-------

[](#license)

Licença Proprietário: owner .

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/9ee8b879db2c5cdc346dd189c6d822fbd4b375f2599e46528ef0662566148b8b?d=identicon)[shieldforce](/maintainers/shieldforce)

---

Top Contributors

[![Shieldforce](https://avatars.githubusercontent.com/u/17112341?v=4)](https://github.com/Shieldforce "Shieldforce (46 commits)")

### Embed Badge

![Health badge](/badges/shieldforce-package-auto-validation-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/shieldforce-package-auto-validation-laravel/health.svg)](https://phpackages.com/packages/shieldforce-package-auto-validation-laravel)
```

###  Alternatives

[marcosh/php-validation-dsl

A DSL for validating data in a functional fashion

483.9k](/packages/marcosh-php-validation-dsl)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
