Download the PHP package laragrad/eloquent-model-validation without Composer
On this page you can find all versions of the php package laragrad/eloquent-model-validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package eloquent-model-validation
laragrad/eloquent-model-validation
This package provides a trait \Laragrad\Models\Concerns\HasValidation
for model validation.
Installing
Run command in console
composer require laragrad/eloquent-model-validation
Using validation
Modify your model
Add into your model next code:
- Use trait
\Laragrad\Models\Concerns\HasValidation
declaration - Validation rules
Controller add() method example
There used next methods provided by \Laragrad\Models\Concerns\HasValidation
trait:
tempFillable()
validate()
HasValidation
trait methods
validate()
Syntax:
validate(array $data = [], array $rules = [], array $messages = [], array $customAttributes = []) : Model
Arguments:
- $data - Validated data. By default model attributes values;
- $rules - Validation rules. By default used $rules property of model;
- $messages - Custom error messages;
- $customAttributes - Custom attribute names for generating validation error messages.
Returns a Model.
Note about $customAttributes argument.
You can define $customAttribute by 3 way:
- Define a
$attributeNames
property of model. - Define translated attribute names in lang files by path
/resources/lang/xx/model/{YourModelPath}.attributes
. For example, for modelApp\Models\ContractType
lang file is/resources/lang/xx/model/app/models/contract_type
- Define a
$customAttributes
argument in thevalidation()
call.
tempFillable()
Syntax:
tempFillable(array $fields) : Model
Arguments:
- $fields - List of fields that you can fill by
fill()
until nextsave()
has called.
Returns a Model.