Skip to content

Commit

Permalink
minor improves
Browse files Browse the repository at this point in the history
  • Loading branch information
AnourValar committed Dec 25, 2019
1 parent f0e398d commit baf138d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/ModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ public function scopeValidate(\Illuminate\Database\Eloquent\Builder $query, $pre
$passes = $validator->passes();

if ($passes && $validator->getRules()) {
$validator = \Validator::make($this->attributes, $validator->getRules());
$validator->setAttributeNames($this->getAttributeNames());
$validator = \Validator::make($validator->getData(), $validator->getRules(), [], $validator->customAttributes);

$passes = $validator->passes();
}
Expand Down
15 changes: 15 additions & 0 deletions src/Providers/EloquentValidationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ public function boot()
});


// "available_keys" validation
\Validator::extend('available_keys', function($attribute, $value, $parameters, $validator)
{
return ( is_array($value) && !array_diff_key($value, array_combine($parameters, $parameters)) );
});

\Validator::replacer('available_keys', function ($message, $attribute, $rule, $parameters, $validator)
{
return trans(
'eloquent-validation::validation.available_keys',
['attribute' => $validator->getDisplayableAttribute($attribute)]
);
});


// langs
$this->loadTranslationsFrom(__DIR__.'/../resources/lang/', 'eloquent-validation');
$this->publishes([__DIR__.'/../resources/lang/' => resource_path('lang/vendor/eloquent-validation')]);
Expand Down
1 change: 1 addition & 0 deletions src/resources/lang/en/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
return [
'scalar' => 'The :attribute must be scalar.',
'config' => 'The :attribute attribute must contain value from directory.',
'available_keys' => 'The :attribute attribute may contain a limited list of keys.',

'calculated' => 'Field :attribute calculated automatically.',
'unchangeable' => 'Field :attribute cannot be changed.',
Expand Down
1 change: 1 addition & 0 deletions src/resources/lang/ru/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
return [
'scalar' => 'Поле :attribute должно быть скалярной величиной.',
'config' => 'Поле :attribute должно содержать значение из справочника.',
'available_keys' => 'Поле :attribute может содержать ограниченный список ключей.',

'calculated' => 'Поле :attribute вычисляется автоматически.',
'unchangeable' => 'Поле :attribute не может быть изменено.',
Expand Down

0 comments on commit baf138d

Please sign in to comment.