Skip to content

Commit

Permalink
improve validation
Browse files Browse the repository at this point in the history
  • Loading branch information
pxpm committed Apr 19, 2024
1 parent e0a9bf2 commit b03b278
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Http/Controllers/TranslationManagerCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,19 @@ private function setupFormFields(bool $forceDisabledFields = false): void

private function getValidationRuleWithLocales(array $rulesToMerge = []): array
{
$rules = collect(config('backpack.crud.locales'))->mapWithKeys(fn ($locale, $key) => ['text.'.$key => 'present'])->toArray();
$locales = config('backpack.crud.locales');
$localesCount = count($locales);

$rules = collect($locales)->mapWithKeys(fn ($locale, $key) => ['text.'.$key => 'bail|present'])->toArray();
$rules['text'] = ['bail', 'min:'.$localesCount, 'max:'.$localesCount];

return array_merge($rules, $rulesToMerge);
}

private function getValidationMessagesWithLocale(array $messagesToMerge = []): array
{
return array_merge(['text.*' => __('backpack.translation-manager::translation_manager.validation_missing_languages')], $messagesToMerge);
return array_merge([
'text.*' => __('backpack.translation-manager::translation_manager.validation_missing_languages')],
$messagesToMerge);
}
}

0 comments on commit b03b278

Please sign in to comment.